While loop in unix reads only first line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting While loop in unix reads only first line
# 1  
Old 05-26-2011
Network 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

Code:
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

Code:
 
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 Smilie Kindly help as soon as possible!! Please Smilie


Moderator's Comments:
Mod Comment Please use [code] and [/code] tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks.

Last edited by zaxxon; 05-26-2011 at 08:07 AM.. Reason: code tags
# 2  
Old 05-26-2011
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
Code:
ssh -T ly228m@$name 'ksh /export/home/ly228m/QDM_QA/bin/OBE_schedule.ksh'

# 3  
Old 05-26-2011
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?
# 4  
Old 05-26-2011
I already did. Read the part of text above the command, and then ask specific questions.
# 5  
Old 05-26-2011
Hard luck..This dint work Smilie i am still stuck up with the same..
# 6  
Old 05-26-2011
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting an unexpected newline in my while loop line-by-line feed

Hi, I'm trying to get a line returned as is from the below input.csv file in Bash in Linux, and somehow I get an unexpected newline in the middle of my input. Here's a sample line in input.csv $> more input.csv TEST_SYSTEM,DUMMY@GMAIL.COM|JULIA H|BROWN And here's a very basic while loop... (7 Replies)
Discussion started by: ChicagoBlues
7 Replies

2. Shell Programming and Scripting

Shell Script that reads a file

I have below script to read a file line by line. How can I ensure that the loop will stop after last line. #!/bin/bash while read -r mod ver tarball; do echo $mod done < taskfile.txt (4 Replies)
Discussion started by: aderamos12
4 Replies

3. UNIX for Advanced & Expert Users

While read line only reads first line in HP-UX B.11.11 system

Hi All, I am facing a strange problem with my code, I have a script which does housekeeping of oracle DB generated files. We have multiple DB's running with different OS users, so we are executing the script as root user, which will generate a dynamic script for each DB, and it will switch to... (8 Replies)
Discussion started by: veeresh_15
8 Replies

4. Shell Programming and Scripting

Reading line by line from live log file using while loop and considering only those lines start from

Hi, I want to read a live log file line by line and considering those line which start from time stamp; Below code I am using, which read line but throws an exception when comparing line that does not contain error code tail -F /logs/COMMON-ERROR.log | while read myline; do... (2 Replies)
Discussion started by: ketanraut
2 Replies

5. Shell Programming and Scripting

UNIX shell script - cut specified line and perform loop

Guys, I have a requirement as below. consider,if i use df command, its getting the below output. file system kbytes used avail %used Mounted on /dev/sample/ 45765 40000 5765 50% / /dev/filesys/ 30000 20000 1000 80% /u .... .... Now i wanted to cut the /u... (11 Replies)
Discussion started by: AraR87
11 Replies

6. UNIX for Dummies Questions & Answers

Difference between buffered disk reads and cached reads?

I was analyzing the Disk read using hdparm utility. This is what i got as a result. # hdparm -t /dev/sda /dev/sda: Timing buffered disk reads: 108 MB in 3.04 seconds = 35.51 MB/sec # hdparm -T /dev/sda /dev/sda: Timing cached reads: 3496 MB in 1.99 seconds = 1756.56 MB/sec... (1 Reply)
Discussion started by: pinga123
1 Replies

7. Shell Programming and Scripting

Illumina reads remove duplicate...

After I using the search tool, I still can't find a solution that was related with my trouble. My input file: @HWI-ABC123_30DFGGDA:1:100:3:1234 ACGTAGTACCCGGGTTTTTTTTTAAAAAAA +HWI-ABC123_30DFGGDA:1:100:3:1234 hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh @HWI-ABC555_30DFGGDA:1:100:3:1234... (14 Replies)
Discussion started by: patrick87
14 Replies

8. UNIX for Advanced & Expert Users

identify the unix process performing high disk i/o reads and writes

Guys, Is there any UNIX command that captures the 'Unix process which is performing high disk I/O reads and writes'. can you help me in this? -Swamy (6 Replies)
Discussion started by: avsswamy
6 Replies

9. Shell Programming and Scripting

identify the unix processes performing high disk i/o reads and writes

I would like to write shell/perl script which identifies the top unix processes that are performing high disk I/O's or/and writes If any one knows the solution please help me? -Swamy (0 Replies)
Discussion started by: avsswamy
0 Replies

10. Programming

scanf doesn´t reads spaces ???

hi all i have a program in C (Unix Solaris 5.7) and i want to read a string from keyboard, but the "scanf" doesn´t reads spaces. example: .... char name; .... printf("Enter your name: "); scanf("%s",&name); printf ("Your name is: %s", name); and if i write Kevin Costner ... (4 Replies)
Discussion started by: DebianJ
4 Replies
Login or Register to Ask a Question