[BALU] Bash Script ssh to server from list file

Vincent Batts vbatts at gmail.com
Thu Apr 7 17:09:28 CDT 2011


If you can help it, the notation of $(cmd) is *much* cleaner. Plus you can
nest, where `` will not allow. Like $(echo $(hostname))

Take care,
vb
On Apr 7, 2011 5:29 PM, "Todd Morgan" <bamamorgans at gmail.com> wrote:
> Woot woot!!!! I see that the single ticks are very specific. I tried them
as
> ' ' and of course it failed. ` is the key.
>
> Thanks!
>
> On Thu, Apr 7, 2011 at 3:58 PM, Walker Haddock <whaddock at mac.com> wrote:
>
>> See below ...
>>
>> On Apr 7, 2011, at 3:40 PM, Todd Morgan wrote:
>>
>> > 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
>> s.b
>> for SERVER in `cat $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
>> > _______________________________________________
>> > Members mailing list
>> > Members at lists.bham-lug.org
>> > http://lists.bham-lug.org/cgi-bin/mailman/listinfo/members
>>
>> _______________________________________________
>> Members mailing list
>> Members at lists.bham-lug.org
>> http://lists.bham-lug.org/cgi-bin/mailman/listinfo/members
>>
>
>
>
> --
> Todd Morgan
> Birmingham, AL
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://bham-lug.org/pipermail/members/attachments/20110407/ab5571ce/attachment.html>


More information about the Members mailing list