LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Working Expect script failing when placed inside bash Loop. (https://www.linuxquestions.org/questions/linux-newbie-8/working-expect-script-failing-when-placed-inside-bash-loop-4175492786/)

Sigmaflux 01-27-2014 04:33 PM

Working Expect script failing when placed inside bash Loop.
 
Hi all,

I have a bash/expect script for connecting to multiple layered devices and working on them. I've tested this script and it works fully IE. test.sh deviceName.

However I want this script to run on a list of devices,
therefore i wrote another bash script which iterates it as such:


while read line
do
DEVICE=$line
test.sh $DEVICE

done <deviceList.txt

When I run it in a loop like this, the expect script simple ends after the first expect command, with no error message or explanation.

Can anyone explain to me why putting this script in a loop is making it faulty?

sag47 01-27-2014 10:51 PM

The test.sh script is most likely expecting something from stdin sort of like when you place ssh in a loop. e.g.

Code:

ssh server1 "ls"
works but the following does not.

Code:

echo "server1
server2" | while read x;do ssh $x "ls";done

However, if you pass null in stdin for ssh then it works.

Code:

echo "server1
server2" | while read x;do ssh $x "ls" < /dev/null;done

See also -n option in ssh man page.

Unless you give more details about your script (such as the source) it is unlikely anybody can help you debug it. Also, you have a bit of redundant variable setting there. Why not just use while read DEVICE if you want to set the $DEVICE variable? There are more improvements that can be made but I'll leave you with that.


All times are GMT -5. The time now is 02:04 AM.