eagertotry
MIS
I am trying to do this:
The file "listofhosts" has one host name per line (about 50 lines). ssh keys have been correctly copied to all the hosts. The script works fine for the first host in the file but comes out (normally, without any error) after that, without looping thru to the next host. If I simply comment out the "ssh" line, the script behaves normally. I am not sure what is the restriction with ssh in such a usage. Using scp instead of ssh allows the script to loop normally. If more than one ssh command is put in the loop, all of them execute exactly once, so script is not even breaking after the first ssh.
Does any one know why ssh above would cause the script not to loop? And, is there a workaround? Essentially, I need to run a command on each of the hosts. I do not have the luxury of using telnet, expect or perl in this environment.
Thanks
Code:
#!/bin/ksh
while read HOST
do
echo "Checking $HOST"
ssh $HOST "ls"
done <listofhosts
The file "listofhosts" has one host name per line (about 50 lines). ssh keys have been correctly copied to all the hosts. The script works fine for the first host in the file but comes out (normally, without any error) after that, without looping thru to the next host. If I simply comment out the "ssh" line, the script behaves normally. I am not sure what is the restriction with ssh in such a usage. Using scp instead of ssh allows the script to loop normally. If more than one ssh command is put in the loop, all of them execute exactly once, so script is not even breaking after the first ssh.
Does any one know why ssh above would cause the script not to loop? And, is there a workaround? Essentially, I need to run a command on each of the hosts. I do not have the luxury of using telnet, expect or perl in this environment.
Thanks