Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

There are several points I'd like to stress in my question.

I'd like to login by asynchronously ssh'ing into our infrastructure equipment. Meaning, I do not want to connect to only one device, do all the tasks I need, disconnect, then connect to the next device. I want to connect to several devices at once in order to make the process as fast as possible.

By equipment I mean 'infrastructure equipment' and not servers. I say this because I will not have the luxury of saving files to the device then transferring them to myself with scp or another method. The output of the scripts that are run will have to be saved directly to my computer.

I will also not be able to use keys in order to automate the login process. The password entry will need to be automated through the script.

The output of the commands that are run will need to be cleaned up and parsed. Also I want the outputs of each device to be combined into one nice and neat file, not a separate file for each device.

This will all be done from a linux box, using ssh, into devices that all use linux'ish proprietary OSes.

My guess is the answer to my question will either be a Bash, Perl, or Python script but I figured it wouldn't hurt to ask and to hear the reasons why one way is better than another.

Thanks everyone.

EXTRA CREDIT: With you answer, include links to resources that will help create the script I described in the language that you suggested.

share|improve this question

closed as not constructive by Zoredache, Sirex, Shane Madden, John Gardeniers, Brent Pabst Dec 13 '12 at 12:59

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

python + fabric. That's essentially what it's for. –  Sirex Dec 12 '12 at 22:30
The requirements of Also I want the outputs of each device to be combined into one nice and neat file, and I want to connect to several devices at once are pretty close to being mutually exclusive. The tool would almost certainly need to write per-device files and then merge them somehow. –  Zoredache Dec 12 '12 at 22:31
@Zoredache thank you. That gives me the strategy to use once I begin coding. –  Fujin Dec 13 '12 at 12:45
@Sirex thank you, implementing that as we speak to test out. –  Fujin Dec 13 '12 at 12:45

1 Answer 1

Parallel SSH (pssh) is perfectly suited to this task, it executes the same command on multiple hosts in parallel. By default pssh will use 32 parallel threads but this number can be increased if required.

Output from the hosts can be logged on the machine that pssh is run from. When logging output pssh will create a text file per host, however your bash script could easily concatenate these.

# pwd

# cat ips.txt

# cat commands.txt
uname -a

# cat
rm -rf /tmp/pssh-output
mkdir -p /tmp/pssh-output
xargs -I {} pssh -h /home/fujin/ips.txt -o /tmp/pssh-output {} < /home/fujin/commands.txt
cat /tmp/pssh-output/* > /tmp/pssh-output/output.txt

# /bin/sh
Success on
Success on
Success on

# ls /tmp/pssh-output  output.txt
share|improve this answer
Great answer. Thank you for the suggestion and example code. I will be testing this solution out along with testing out fabric. –  Fujin Dec 13 '12 at 12:47
This script lacks the code to put in the password for logging in with SSH. I'm currently looking through the documentation to see if automating pw entry is possible with pssh. –  Fujin Dec 13 '12 at 16:09
I don't believe it does, it expects to use public key authentication with ssh-agent. You might want to edit your question and call out the need for keyboard-interactive authentication if that's a requirement. –  mcourtney Dec 13 '12 at 21:31

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