OT: bash script - unexpected exit

Kevin Martin kevintm at ameritech.net
Mon Jan 16 16:50:21 UTC 2012



On 01/16/2012 10:29 AM, Hiisi wrote:
> Hi, list.
> Sorry for OT. I like this list and really appreciate your help. Please
> excuse me if this post irritates you.
> I want to write a bash script that will do some work on a LAN. Here's
> the script (at least I execute it on Fedora machine ):
> #!/bin/sh
>
> set -e
>
> cat hosts | while read line
> do
> 	if (! grep -q repo.corp.macros /etc/apt/sources.list ); then
> 	echo $?
> 	sshpass -p '*****' ssh -o UserKnownHostsFile=/dev/null -o
> StrictHostKeyChecking=no -o ConnectTimeout=3 master@$line 'echo
> "*****" | sudo -S sed "s/http:\/\//http:\/\/repo.corp.macros:3142\//g"
> /etc/apt/sources.list > /home/master/sdjhfklj' ; echo $?
> 	sshpass -p '*****' ssh -o UserKnownHostsFile=/dev/null -o
> StrictHostKeyChecking=no -o ConnectTimeout=3 master@$line 'echo
> "*****" | sudo -S echo "deb
> http://repo.corp.macros:3142/apt-cache/repo /" >>
> /home/master/sdjhfklj' ; echo $?
> 	sshpass -p '*****' ssh -o UserKnownHostsFile=/dev/null -o
> StrictHostKeyChecking=no -o ConnectTimeout=3 master@$line 'echo
> "*****" | sudo -S mv /home/master/sdjhfklj /etc/apt/sources.list';
> echo $?
> 	fi
> done
>
> The problem is that it never works for more than one host. I.e. in
> hosts file there's 36 hosts. The script works as expected on the first
> one and then it exits. ERRORLEVEL ($?) is always zero at each point.
> What am I doing wrong and how to modify it?
> TIA
put a 'set -x' in there so you can see what's happening during the execution.  It would be interesting to know what $line is getting
set to.  You may be surprised.

Kevin


More information about the users mailing list