Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

i would like to find a program that maintains a list of commands that can be aliased for different hosts. for example, we have a database server, and four web servers. a common task is to login to the admin server and restart mysql using

# ssh dbserver "service mysql restart"

then we restart each of the web servers by running

# ssh webserver1 "service apache2 restart"
# ssh webserver2 "service apache2 restart"
# ssh webserver3 "service apache2 restart"
# ssh webserver4 "service apache2 restart"

I would like to have an package that keeps track of these commands and i could run them as such:

# blah dbserver,webserver1-4 "restartServices"

then it would loop through each host listed and run the commands necessary to restart the services on those boxes.

share|improve this question
    
adding information: we have over 2500 systems and remembering the list of commands to restart X service on Y system is cumbersome. –  jaymz Jun 29 '12 at 23:22
5  
If you have 2500 systems then may I suggest, that you may be looking at this completely backwards, and instead you should be looking for something like puppet + mcollective. –  Zoredache Jun 30 '12 at 0:03
2  
Please include additional details in the question itself, not in comments. –  EEAA Jun 30 '12 at 0:53
    
@Zoredache do you have an example of how mcollective would accomplish this? –  jaymz Jul 2 '12 at 20:09
    
I haven't actually used mcollective, just read a bit about it when I was reading through Pro Puppet. I deal with a smaller set, and I suspect far more diverse set of servers. I am not sure mcollective would be as useful for what I am doing. From what I understand basically allow you to issue commands to a group of system that you can specify based on a large number of facts provided by facter that can be filtered with regular expressions. If you are interested, I suggest you grab a copy of the book I linked to. –  Zoredache Jul 2 '12 at 20:40
show 2 more comments

3 Answers

You can write your own bash script for this.

#!/bin/bash
ssh server 1 "service apache2 restart"
ssh server 2 "service apache2 restart"
ssh server 3 "service apache2 restart" etc....

Then just run the script.

share|improve this answer
    
Thanks for the suggestion, but we have 2500 servers with random start and stop commands. It's extremely difficult to remember them all and i don't want to do them in the same order every time. for example, what if i only want to restart the dbserver and a couple of the web servers? I will add information to my post to clarify the requirements. –  jaymz Jun 29 '12 at 23:17
    
If you only want to restart the dbserver and a couple of the webservers, then... only restart the dbserver and a couple of the webservers. You can do all sorts of things with shell scripts. –  womble Jun 30 '12 at 1:59
    
... and if you want even more control, then use variables in the script to group multiple servers together and/or execute on stand-alone machines. Maybe something like ./run-my-script {server x} {server-group y}. –  David W Jun 30 '12 at 11:32
add comment

This can be done in a few ways.

Perhaps the most simple way would be to use pssh (parallel ssh).

If your needs are more complex, you can use a framework like Fabric or MCollective.

share|improve this answer
    
from what i can tell, pssh only will execute the same command on multiple systems. i'm looking for a command that helps keep a list of what commands i need to run. then using aliases i can use the same command to restart different services depending on which host i am trying to administer. i've looked at fabric and it is interesting but seems like more of a 'batch' system? is there some tutorial you know of that shows how to use it more flexibly? –  jaymz Jun 29 '12 at 23:19
    
Well you gave a pretty irrelevant example then. In as large of an environment as you have, you're already way behind the game if you don't have this sorted already. As zoredache mentioned above, look into puppet and mcollective. You're going to need to do a large amount of customization regardless of what solution you choose. –  EEAA Jun 30 '12 at 0:26
    
"keep a list of what commands i need to run" -- that is the very definition of a shell script. –  womble Jun 30 '12 at 1:58
    
The example is exactly what i want. I've looked at fabric a bit deeper now, and I still can't see a way to get it where i need it. With a fabfile.py set out like this: from fabric.api import run, env, roles env.roledefs = { 'web': ['localhost'], 'dns': ['172.25.16.55'] } @roles('dns') def taskA(): run('ls') @roles('web') def taskA(): run('whoami') –  jaymz Jul 2 '12 at 19:58
    
the above did not format correctly, but what i am looking for is a way to get fabric to run the following command: fab -R dns,web taskA where taskA runs different commands on dns then it does web. –  jaymz Jul 2 '12 at 20:08
add comment

It sounds to me like what you want is rundeck. It comes with a nice web interface, but also works just as well on the command line.

share|improve this answer
    
that looks promising, i will look into that. thanks. –  jaymz Jul 2 '12 at 21:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.