Saturday, March 9, 2013

sshpass for remote command execution

sshpass is a utility designed for running ssh using the mode referred to as "keyboard-interactive" password authentication, but in non-interactive mode.

#sudo apt-get install sshpass
Logint to a remote macine
$ sshpass -p 'your_secret_Pass' ssh username@server.yourDomain.com

Create a script to run the command on multiple machines

root@myMachine:/var/local/scritps# cat remote_cmd_script.sh
LIST=`/bin/cat /var/local/scripts/machineListFile.txt`
for i in $LIST
do
 echo $i
 sshpass -p 'xxxxx' ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@$i.myDomain.com $1
 echo " "
done

run the command from terminal

#./remote_cmd_script "ps aux | grep mysql"

No comments:

Post a Comment