Article 6P6FP bash while loop terminating on ssh

bash while loop terminating on ssh

by
mfoley
from LinuxQuestions.org on (#6P6FP)
I have the following in a bash script:
Code:ls -1 $HOME/VirtualBox\ VMs | while read
do
echo ">> vm: $REPLY"

if [ "$REPLY" = "WEBSERVER" ]
then
f=`ssh user@mydom.org ls -ltr /mnt/OHPRSbackup/public | grep publicFullBackup | tail -1 | \
awk '{print $NF}' | sed 's#^#/mnt/OHPRSbackup/public/#'`
fi

if [ "$REPLY" = "dbserver" ]
then
echo 'YES!!!'
fi

doneIf I put a 'continue' right after the echo ">> vm: $REPLY" I get:
Code:>> vm: MAIL
>> vm: WEBSERVER
>> vm: dbserveras expected. Otherwise it will do the ssh, then exit the loop. It does not do the if [ "$REPLY" = "dbserver" ].

For other commands instead of 'ssh', for example 'ls', it works and goes on to display "YES!!!". What is it about this ssh command that is causing the loop to terminate after doing the if [ "$REPLY" = "WEBSERVER" ]?

When it executes the ssh I do have to enter the password, but that shouldn't be a problem. I've also tried using sshpass so I don't have to enter the password manually. Same problem.

It's as if the loop variable $REPLY gets cleared. Note that if I specify some variable other than $REPLY I get the same loop termination results. It must be related to ssh somehow?

Ideas?
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments