While loop breaking when using "ssh" command inside

Hi ,

I am trying to read a list of hosts from a config file and trying to get file list from that host. For this I have used one while loop.

cat "$ARCHIVE_CFG_FILE" |  sed '/^$/d' | sed '/^#/d' | while read ARCHIVE_CFG
do 
    SOURCE_SERVER_NAME=`echo "$ARCHIVE_CFG" | awk -F '|' '{ print $1 }'`
    SOURCE_FOLDER_NAME=`echo "$ARCHIVE_CFG" | awk -F '|' '{ print $2 }'`
    LOAD_FILE_NAME=`echo "$ARCHIVE_CFG" | awk -F '|' '{ print $3 }'`
    ARCHIVE_FOLDER=`echo "$ARCHIVE_CFG" | awk -F '|' '{ print $4 }'` 
    ARCHIVE_DELAY=`echo "$ARCHIVE_CFG" | awk -F '|' '{ print $5 }'`
    TEMP_SFTP_FILE="census_.$$.sftp"

    step_message="checking config variables"
    if [ "$SOURCE_SERVER_NAME" = "" ] || [ "$SOURCE_FOLDER_NAME" = "" ] || [ "$LOAD_FILE_NAME" = "" ] || [ "$ARCHIVE_FOLDER" = "" ] || [ "$ARCHIVE_DELAY" = "" ] || [ "$TEMP_SFTP_FILE" = "" ]
    then 
        log 3 "$step_message"
    else
        log 5 "$step_message"
    fi

    log 5 "================================================="
    log 5 "SOURCE_SERVER_NAME\t:\t$SOURCE_SERVER_NAME"
    log 5 "SOURCE_FOLDER_NAME\t:\t$SOURCE_FOLDER_NAME"
    log 5 "LOAD_FILE_NAME\t\t:\t$LOAD_FILE_NAME"
    log 5 "ARCHIVE_FOLDER\t\t:\t$ARCHIVE_FOLDER"
    log 5 "ARCHIVE_DELAY\t\t\t:\t$ARCHIVE_DELAY days"
    log 5 "TEMP_SFTP_FILE\t\t:\t$TEMP_SFTP_FILE"
    log 5 "================================================="
    
        #Getting file archive list from remote server
    step_message="Getting file archive list from remote server"
    FILELIST=`ssh $SOURCE_SERVER_NAME find $SOURCE_FOLDER_NAME -type f -mtime +$ARCHIVE_DELAY | grep "$SOURCE_FOLDER_NAME/$LOAD_FILE_NAME"`
    echo $?
    
done

But when I am using the ssh command inside this while loop the loop is breaking and I am not getting any more file list of next host.

Can anyone please suggest what is the issue and how to overcome this?

ARCHIVE_CFG_FILE = config file containing multiple host details
log is a function for logging.

Hint 1: use

$( command )

instead of

`command`

. Makes it more readable, and it's nestable too.

Hint 2: The ssh command has the nasty "feature" of grabbing all input on STDIN and pushing it through to the commands on the remote host. Nice for pipes, less nice for outer loops reading from a pipe. Change your connection line to

FILELIST=$( ssh $SOURCE_SERVER_NAME find $SOURCE_FOLDER_NAME -type f -mtime +$ARCHIVE_DELAY < /dev/null | grep "$SOURCE_FOLDER_NAME/$LOAD_FILE_NAME" )

and you should be fine.

Try this

FILELIST=$(ssh -n $SOURCE_SERVER_NAME find $SOURCE_FOLDER_NAME -type f -mtime +$ARCHIVE_DELAY < /dev/null | grep "$SOURCE_FOLDER_NAME/$LOAD_FILE_NAME" )