LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-27-2014, 05:33 PM   #1
Sigmaflux
LQ Newbie
 
Registered: Jan 2014
Posts: 1

Rep: Reputation: Disabled
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?
 
Old 01-27-2014, 11:51 PM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,831
Blog Entries: 36

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
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.

Last edited by sag47; 01-27-2014 at 11:57 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script issue (for loop inside a loop) Mperonen Programming 3 08-08-2013 03:14 AM
[SOLVED] echo command inside expect script Soji Antony Linux - Newbie 2 11-23-2011 07:50 AM
Expect script with loop does not work zongbot Programming 5 08-31-2011 02:19 PM
[SOLVED] /usr/bin/expect : Script to check server load using both expect and bash Soji Antony Programming 1 07-28-2010 12:27 AM
expect script - for argument loop ? nilleso Linux - Software 3 09-16-2009 09:51 PM


All times are GMT -5. The time now is 04:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration