LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 05-01-2008, 11:40 AM   #1
steven.c.banks
Member
 
Registered: Dec 2007
Location: Virginia
Distribution: RHEL
Posts: 44
Blog Entries: 1

Rep: Reputation: 15
Unhappy Unexpected result in while do done loop reading file


I have this while do done loop in a bash shell script:

while read line;
do
echo $line
ssh root@anotherserver "hostname"
echo "here1"
done </tmp/get_mbx_stats.tmp

It reads the first line of /tmp/get_mbx_stats.tmp OK, and I get the correct results from the ssh and the echo commands, but then it drops out of the loop, even though there are many more lines in /tmp/get_mbx_stats.tmp.

If I comment out the ssh command, it works as expected - it reads and echoes all the lines in the input file.

I have tried many variations but they always fail with the same issue.

(Actually I need to get information from "anotherserver" - not simply its hostname - but I boiled it down to the simplest ssh I could think of).

Is the ssh command changing the file status in some way?

Thanks in advance...

Last edited by steven.c.banks; 05-01-2008 at 11:54 AM.
 
Old 05-01-2008, 01:12 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
This is a known issue with ssh trying to read from standard input and sending a SIGTTIN signal to the parent shell upon exit. You can try the option -n of ssh, that circumvent this problem, redirecting standard input from /dev/null or explicitly redirect standard input in the ssh command line:
Code:
ssh -n root@anotherserver "hostname"
ssh root@anotherserver "hostname" < /dev/null
 
Old 05-01-2008, 01:32 PM   #3
steven.c.banks
Member
 
Registered: Dec 2007
Location: Virginia
Distribution: RHEL
Posts: 44
Blog Entries: 1

Original Poster
Rep: Reputation: 15
Thank you!!! I used the -n option, and that fixed the problem!!
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 8 04-05-2011 10:18 AM
BASH: Reading long filenames into an array using a loop DaneM Programming 12 09-11-2009 08:24 AM
mysql count(*) unexpected result kpachopoulos Programming 3 01-03-2008 11:08 AM
MySQL queries from Shell - unexpected result philipz Programming 5 05-04-2004 06:38 PM
cp command problem..... unexpected result hamster Linux - General 2 04-10-2003 05:57 PM


All times are GMT -5. The time now is 02:38 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration