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

Create a script to run the command on multiple machines

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

run the command from terminal

#./remote_cmd_script "ps aux | grep mysql"

No comments:

Post a Comment