Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

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

done < $hfile

file hfile
user1  pas1
user2  pas2
user3  pas3
share|improve this question
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

Your Answer


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.