Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 01-27-2014, 04:33 PM   #1
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. 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

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, 10:51 PM   #2
Senior Member
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,860
Blog Entries: 36

Rep: Reputation: 458Reputation: 458Reputation: 458Reputation: 458Reputation: 458
The script is most likely expecting something from stdin sort of like when you place ssh in a loop. e.g.

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

echo "server1
server2" | while read x;do ssh $x "ls";done
However, if you pass null in stdin for ssh then it works.

 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 10:57 PM.


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 02:14 AM
[SOLVED] echo command inside expect script Soji Antony Linux - Newbie 2 11-23-2011 06:50 AM
Expect script with loop does not work zongbot Programming 5 08-31-2011 01:19 PM
[SOLVED] /usr/bin/expect : Script to check server load using both expect and bash Soji Antony Programming 1 07-27-2010 11:27 PM
expect script - for argument loop ? nilleso Linux - Software 3 09-16-2009 08:51 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:30 AM.

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