I am writing a script to get the command information of the remote machine usinf while and for loop. PFB the script. But the script ends by giving the single command information only. I have multiple commands in this file (CMDS=$HOMEDIR/cmnd.txt)
. If I don't use ssh all the commands working fine, but when I use ssh it executes first command only.
#!/bin/bash
HOMEDIR=/home/448130
CMDS=$HOMEDIR/cmnd.txt
while read -r line
do
for i in $(cat hostname.txt);
do
echo "***************************** $line output begins ********************************";
#echo $line
ssh $i $line
echo "***************************** $line output ends ********************************";
done
done < $CMDS
Please help me to fix this.
You may find several methods for running local commands remotely at http://backreference.org/2011/08/10/running-local-script-remotely-with-arguments/
And a pretty similar question: http://stackoverflow.com/questions/8376166/execute-a-command-on-remote-hosts-via-ssh-from-inside-a-bash-script
– doktor5000 May 20 '15 at 07:48