While loop in unix reads only first line

Hi,
I am in need of help on reading through a file(servernames.dat) which has a list of server names, while it reads each file name it has to connect to that server and run another script, once it has executed the script on one server, it has to go back to the list of servernames to get the next server name and do the same.

The issue is wiht reading through the svrnames.dat file, it reads first line, executes the script on that server and exits from teh script.
The code i have tried are below

set -x
# Set the Path of Environment file
ENV_FILE_DIR=/opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/bin
LOG_DIR=/opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/log
export ENV_FILE_DIR
export LOG_DIR
# Set Audit Environment
. ${ENV_FILE_DIR}/QDM.env
export LOGFILE=${LOG_DIR}/obj_`date +%Y%m%d`.log
:>${LOGFILE}
SVRNM=${QDM_CFG_DIR}/svrnames.dat
while read servername
do
export name=$servername
ssh ly228m@$name ksh /export/home/ly228m/QDM_QA/bin/OBE_schedule.ksh
RC=$?
if [[ ${RC} -ne 0 ]] then
   echo "\n ERROR- Executing the object script on $servername \n"
       exit 1;
fi
done < $SVRNM
exit

I had also tried

 
set -x
# Set the Path of Environment file
ENV_FILE_DIR=/opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/bin
LOG_DIR=/opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/log
export ENV_FILE_DIR
export LOG_DIR
# Set Audit Environment
. ${ENV_FILE_DIR}/QDM.env
export LOGFILE=${LOG_DIR}/obj_`date +%Y%m%d`.log
:>${LOGFILE}
SVRNM=${QDM_CFG_DIR}/svrnames.dat
i=0
while read line
do
echo $line | read servername
export name=$servername
ssh ly228m@$name ksh /export/home/ly228m/QDM_QA/bin/OBE_schedule.ksh
RC=$?
if [[ ${RC} -ne 0 ]] then
   echo "\n ERROR- Executing the object script on $servername \n"
       exit 1;
fi
i=$(( i+1 ))
done < $SVRNM
exit

in the log, once it is done with the first server, it goes back to the while command prints "read servername" and then exits!
I intend to do the same for 16 servers :frowning: Kindly help as soon as possible!! Please :frowning:

When reading a file this way, the contents are available to all programs called within. And the ssh client will usually read as much information from stdin as possible, and send it to the remote side, even if not used. Disable the TTY allocation by running ssh as

ssh -T ly228m@$name 'ksh /export/home/ly228m/QDM_QA/bin/OBE_schedule.ksh'

Thanks for the information.. However,am new to unix and shell scripting..can you please explain on why i should use the above that you have mentioned?

I already did. Read the part of text above the command, and then ask specific questions.

Hard luck..This dint work :frowning: i am still stuck up with the same..

I am not sure if this has in the end the same effect as -T, but I usually use -n for ssh when running it inside a loop.