LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 10: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 10:54 AM.
 
Old 05-01-2008, 12:12 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 12:32 PM   #3
steven.c.banks
Member
 
Registered: Dec 2007
Location: Virginia
Distribution: RHEL
Posts: 44

Original Poster
Blog Entries: 1

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


Reply



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 9 07-28-2015 03:49 PM
BASH: Reading long filenames into an array using a loop DaneM Programming 12 09-11-2009 07:24 AM
mysql count(*) unexpected result kpachopoulos Programming 3 01-03-2008 10:08 AM
MySQL queries from Shell - unexpected result philipz Programming 5 05-04-2004 05:38 PM
cp command problem..... unexpected result hamster Linux - General 2 04-10-2003 04:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:28 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
Open Source Consulting | Domain Registration