- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: while read line only reads the first line when...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2011 06:55 AM - edited 10-27-2011 06:59 AM
10-27-2011 06:55 AM - edited 10-27-2011 06:59 AM
while read line only reads the first line when passing to a script
First off - this is weird - going to take sometime getting used to these forums...I'm having ITRC withdrawal.
Okay, so I have a file...currrently has 9 lines (could have more could have less).
Each line has 7 variables that I want to pass to a script.
So, in come while read line:
while read line do ./exe.backup.ksh $line done <list
That only processes the first line :(
Echo works:
while read line do echo $line echo " " done <list z_vbwaqa22 QB4 qb4adm /usr/sap/QB4/D06/exe /usr/sap/QB4/D06/exe.new /sapmnt/QB4/exe /sapmnt/QB4/exe.new z_vbwjqa22 QB7 qb7adm /usr/sap/QB7/J09/exe /usr/sap/QB7/J09/exe.new /sapmnt/QB7/exe /sapmnt/QB7/exe.new z_vcuaqa21 QU3 qu3adm /usr/sap/QU3/DVEBMGS36/exe /usr/sap/QU3/DVEBMGS36/exe.new /sapmnt/QU3/exe /sapmnt/QU3/exe.new z_vecaqa22 QR3 qr3adm /usr/sap/QR3/D01/exe /usr/sap/QR3/D01/exe.new /sapmnt/QR3/exe /sapmnt/QR3/exe.new z_vecjqa22 QR7 qr7adm /usr/sap/QR7/J04/exe /usr/sap/QR7/J04/exe.new /sapmnt/QR7/exe /sapmnt/QR7/exe.new z_vepjqa21 QP6 qp6adm /usr/sap/QP6/JC63/exe /usr/sap/QP6/JC63/exe.new /sapmnt/QP6/exe /sapmnt/QP6/exe.new z_vgrjqa22 QG6 qg6adm /usr/sap/QG6/J84/exe /usr/sap/QG6/J84/exe.new /sapmnt/QG6/exe /sapmnt/QG6/exe.new z_vpiaqa22 QX3 qx3adm /usr/sap/QX3/D31/exe /usr/sap/QX3/D31/exe.new /sapmnt/QX3/exe /sapmnt/QX3/exe.new z_vsraqa22 QY3 qy3adm /usr/sap/QY3/D11/exe /usr/sap/QY3/D11/exe.new /sapmnt/QY3/exe /sapmnt/QY3/exe.new
Here's the script:
#!/bin/ksh # backup the exe dirs # gwild 10262011 # # # Do you want to pass a file to this script? # Put the 3 variables on a single line in a file named for example "list": # z_vbwaqa21 qb4adm QB4 /usr/sap/QB4/DVEBMGS06/exe /sapmnt/QB4/exe /usr/sap/QB4/DVEBMGS06/exe.new /sapmnt/QB4/exe.new # # Then run the script like so: # # while read line # do # ./exe.backup.ksh $line # done <list # # variables LOG=/tmp/exe.backup.log # check for parameters else give usage if [ $# -lt 1 -o \( $# -gt 7 -a $# -lt 7 \) ] then echo "Usage:" echo "exe.backup.ksh \"zone\" \"SID\" \"sidadm\" \"SRC1\" \"TRG1\" \"SRC2\" \"TRG2\"" echo "Example:" echo "exe.backup.ksh z_vbwaqa21 QB4 qb4adm /usr/sap/QB4/DVEBMGS06/exe /usr/sap/QB4/DVEBMGS06/exe.new /sapmnt/QB4/exe /sapmnt/QB4/exe.new" echo " " echo "Note: results in $LOG" exit 1 fi echo " " ZON=$1 SID=$2 ADM=$3 SRC1=$4 TRG1=$5 SRC2=$6 TRG2=$7 date >> $LOG zlogin $ZON "su - $ADM -c 'echo "$SID" ; uname -n ; mkdir $TRG1 ; cd $SRC1 ; tar cf - * | ( cd $TRG1; tar xfp -) ; echo "how many files in $SRC1 ?" ; find $SRC1 |wc -l ; echo "How many files in $TRG1 ?" ; find $TRG1 |wc -l'" >>$LOG date >> $LOG zlogin $ZON "su - $ADM -c 'echo "$SID" ; uname -n ; mkdir $TRG2 ; cd $SRC2 ; tar cf - * | ( cd $TRG2; tar xfp -) ; echo "how many files in $SRC2 ?" ; find $SRC2 |wc -l ; echo "How many files in $TRG2 ?" ; find $TRG2 |wc -l'" >>$LOG date >> $LOG
So, what am I doing wrong?
Kirk: Maybe he's not out there, Bones. Maybe he's right here. [points to his heart]
- Tags:
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2011 08:43 AM
10-27-2011 08:43 AM
Re: while read line only reads the first line when passing to a script
Seems the issue is with zlogin itself....sigh....
Kirk: Maybe he's not out there, Bones. Maybe he's right here. [points to his heart]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2011 08:51 AM
10-27-2011 08:51 AM
Re: while read line only reads the first line when passing to a script
hi:
Why this line?
if [ $# -lt 1 -o \( $# -gt 7 -a $# -lt 7 \) ]
If you want to verify that you have seven arguments, do:
if [ $# -ne 7 ]
But then your comments note: "# Do you want to pass a file to this script? # Put the 3 variables on a single line in a file named for example "list":"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2011 11:36 AM
10-27-2011 11:36 AM
Re: while read line only reads the first line when passing to a script
work around:
#!/bin/ksh # backup the exe dirs # gwild 10262011 # # # Do you want to pass a file to this script? ###################################################################################################################### # TOO BAD - zlogin always breaks out of a while loop so you will have to run this script manually for every zone. ###################################################################################################################### # UPDATE - found a workaround by just creating a tmp file with the zlogin command - yet you can NOT just cut and paste # it into your session - you have to sh it: sh /tmp/exe.backup.tmp ###################################################################################################################### # Put the 7 variables on a single line in a file named for example "list": # z_vbwaqa21 qb4adm QB4 /usr/sap/QB4/DVEBMGS06/exe /sapmnt/QB4/exe /usr/sap/QB4/DVEBMGS06/exe.new /sapmnt/QB4/exe.new # # Then run the script like so: # # while read line # do # ./exe.backup.ksh ${line} # done <list # # variables LOG=/tmp/exe.backup.log SHFILE=/tmp/exe.backup.tmp # check for parameters else give usage if [ $# -ne 7 ] then echo "Usage:" echo "exe.backup.ksh \"zone\" \"SID\" \"sidadm\" \"SRC1\" \"TRG1\" \"SRC2\" \"TRG2\"" echo "Example:" echo "exe.backup.ksh z_vbwaqa21 QB4 qb4adm /usr/sap/QB4/DVEBMGS06/exe /usr/sap/QB4/DVEBMGS06/exe.new /sapmnt/QB4/exe /sap mnt/QB4/exe.new" echo " " echo "Note: results in $LOG" exit 1 fi ZON=$1 SID=$2 ADM=$3 SRC1=$4 TRG1=$5 SRC2=$6 TRG2=$7 date >> $LOG echo "zlogin $ZON \"su - $ADM -c 'echo $SID ; uname -n ; mkdir $TRG1 ; cd $SRC1 ; tar cf - * | ( cd $TRG1; tar xfp -) ; echo "how many files in $SRC1 ?" ; find $SRC1 |wc -l ; echo "How many files in $TRG1 ?" ; find $TRG1 |wc -l'\"" >>$SHFILE echo "zlogin $ZON \"su - $ADM -c 'echo $SID ; uname -n ; mkdir $TRG2 ; cd $SRC2 ; tar cf - * | ( cd $TRG2; tar xfp -) ; echo "how many files in $SRC2 ?" ; find $SRC2 |wc -l ; echo "How many files in $TRG2 ?" ; find $TRG2 |wc -l'\"" >>$SHFILE
Kirk: Maybe he's not out there, Bones. Maybe he's right here. [points to his heart]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2011 12:08 PM
10-27-2011 12:08 PM
Re: while read line only reads the first line when passing to a script
Hi (again):
> # TOO BAD - zlogin always breaks out of a while loop so you will have to run this script manually for every zone.
This isn't HP-UX. Rather is appears to be Sun-OS. I'd suggest a non-HP community or at least an agnostic UNIX/Linux one in the future :-)
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2011 12:31 PM
10-27-2011 12:31 PM
Re: while read line only reads the first line when passing to a script
Unfortunately, Solaris admins tend to keep to themselves - in other words, I would never get any help from one of them. ;)
Kirk: Maybe he's not out there, Bones. Maybe he's right here. [points to his heart]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2011 08:07 PM
10-27-2011 08:07 PM
Re: while read line only reads the first line when passing to a script
>Each line has 7 variables that I want to pass to a script.
If you have 7 variables, you should really read 7 values: (Use more descriptive names)
while read v1 v2 v3 v4 v5 v6 v7; do
./exe.backup.ksh $v1 $v2 $v3 $v4 $v5 $v6 $v7
>echo works:
Not really. You don't know if there are one parm or 7.