-1

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
Chetan Bhargava
  • 245
  • 5
  • 15
Arn
  • 13
  • 5

1 Answers1

0

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)...

user9517
  • 114,104
  • 20
  • 206
  • 289