There is a list of IP addresses in a .txt file, ex.:
1.1.1.1
2.2.2.2
3.3.3.3
Behind every IP address there is a server, and on every server there is an sshd running on port 22. Not every server is in the known_hosts
list (on my PC, Ubuntu 10.04 LTS/bash).
How can I run commands on these servers, and collect the output?
Ideally, I'd like to run the commands in parallel on all the servers.
I'll be using public key authentication on all the servers.
Here are some potential pitfalls:
known_hosts
file.The servers are AIX/ksh (but I think that doesn't really matter.
Assuming that you are not able to get pssh or others installed, you could do something similar to:
tmpdir=${TMPDIR:-/tmp}/pssh.$$
mkdir -p $tmpdir
count=0
while IFS= read -r userhost; do
ssh -n -o BatchMode=yes ${userhost} 'uname -a' > ${tmpdir}/${userhost} 2>&1 &
count=`expr $count + 1`
done < userhost.lst
while [ $count -gt 0 ]; do
wait $pids
count=`expr $count - 1`
done
echo "Output for hosts are in $tmpdir"
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments