Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am running a shell script with a while loop and it exits with the below error, how could I avoid it or catch the error and let the loop to continue ? ie how could I handle the exception

stty: standard input: Invalid argument

Following are the script I am trying but it exit from the loop after the first iteration.

hfile=/tmp/prty.txt
while read property
do
 hostname=`echo $property | awk '{print $1}'`
 echo $hostname
 ssh -l gger $hostname ". <userhome>/.bash_profile; ggsci -v; exit  << EOF > /tmp/gg.txt

 EOF"
done < $hfile

file hfile
==========
user1  pas1
user2  pas2
user3  pas3
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Now that I've had more caffeine I can see that the error message you are getting is a red herring.

At the point that you execute ssh it is given control of stdin which it will fully consume. This means that it will read the data from $hfile which in turn means that after one iteration of the loop the while ends.

You can use the -n switch to ssh to solve this problem.

ssh -n -l gger $hostname ". <us...

-n Redirects stdin from /dev/null (actually, prevents reading from stdin)...

share|improve this answer
    
@Arn: See my latest update –  Iain Dec 22 '12 at 9:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.