Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ssh breaking out of while loop??? 1

Status
Not open for further replies.

bgreen

Programmer
Feb 20, 2003
185
CA
Hi,

The following code is causing my while loop to end. The reason is the ssh code. I need to go to another host and display the last line of each file that exists. How ccan I do this without breaking out? I only get the output from one file when there are actually multiple files to display lines from.

ssh ${FRHOST} ls "${CHKOUT_FILES}/${CPFILE}.ckoutlog*" | awk -
F"chkoutlog\/" '{print $2}' > $CHKOUTLOG_LIST


while read line
do
print "\n-> ${CHKOUT_FILES}/${line}\n exists on ${FRHOST}"
MSG=`ssh ${FRHOST} tail -1 "${CHKOUT_FILES}/${line}"`
print "${MSG}"
continue
done < $CHKOUTLOG_LIST
 
And what about ssh -n ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
a common problem...

see man page for ssh

use -n flag to make ssh not read stdin. Your first ssh command otherwise "eats" all stdin which would be waiting for next while read line iteration.

Another solution is:

ssh whichever_host whatever_cmd_line </dev/null

to prevent eating away at stdin...

HTH,

p5wizard
 
One possible solution is to use a different file descriptor as such:

Code:
ssh ${FRHOST} ls "${CHKOUT_FILES}/${CPFILE}.ckoutlog*" | awk -
F"chkoutlog\/" '{print $2}' > $CHKOUTLOG_LIST

while read -u3 line
do
      print "\n-> ${CHKOUT_FILES}/${line}\n   exists on ${FRHOST}"
      MSG=`ssh ${FRHOST} tail -1 "${CHKOUT_FILES}/${line}"`
      print "${MSG}"
      continue
done 3< $CHKOUTLOG_LIST

Regards,
Chuck
 
I like cspilman's answer. It works splendidly!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top