[BALU] Bash Script ssh to server from list file

Todd Morgan bamamorgans at gmail.com
Thu Apr 7 15:40:51 CDT 2011


So I'm finishing up a bash script wrote that will ultimately loop through
some code which includes a few ssh commands. The hostnames of the boxes I'm
logging into are in a server_list file. For some reason the script will run
for the first name in the list but quit after that. Here's what I've tried.

version 1 - Will only work for the first entry in the $SERVER_LIST file

while read SERVER
do
OTHER_VAR=new-$SERVER (not particularly important to the issue, but I
thought I would include it)
ssh $SERVER exec $some_command1
ssh $SERVER exec $some_command2
ssh $SERVER exec $some_command3
done < $SERVER_LIST
--------
Version 2 - same results as #1

cat $SERVER_LIST |

while read SERVER
do
OTHER_VAR=new-$SERVER (not particularly important to the issue, but I
thought I would include it)
ssh $SERVER exec $some_command1
ssh $SERVER exec $some_command2
ssh $SERVER exec $some_command3
done
-------
version 3 - this one failed miserably

for SERVER in $SERVER_LIST
do
OTHER_VAR=new-$SERVER (not particularly important to the issue, but I
thought I would include it)
ssh $SERVER exec $some_command1
ssh $SERVER exec $some_command2
ssh $SERVER exec $some_command3
done
------

Don't know if this is particularly relevant, but the $some_command variables
are defined outside of the loop, but modified slightly inside the while
statement.

If I do a VERY basic while loop with echo's I'm fine

while read SERVER
do
echo $SERVER
$SERVER='diff-name'
echo $SERVER
done < $SERVER_LIST

It iterates through the loop echos out what you'd expect. Any help you can
provide would be appreciated. Thanks

-- 
Todd Morgan
Birmingham, AL
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://bham-lug.org/pipermail/members/attachments/20110407/94fba237/attachment.html>


More information about the Members mailing list