While loop Error in one line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting While loop Error in one line
# 1  
Old 12-23-2017
IBM While loop Error in one line

Code:
ssh -q Node_name lspv |egrep -w 'hdisk0|hdisk1' |awk '{print $1}' |while read line; do echo $line " " ssh -q Node_name `bootinfo -s $line`;done

Please let me know why i getting this error

Last edited by jim mcnamara; 12-23-2017 at 01:25 PM..
# 2  
Old 12-23-2017
You are missing a lot of quotes, but it is hard to untangle.
What I do:

1. create a multiline script that works when on my home box ( assuming it is the same as the remote, otherwise create the code over on the remote)

2. scp -p the script to the remote

3.
Code:
ssh Node_name /path/to/myscript.sh

# 3  
Old 12-23-2017
Hi Jim,
Thanks for your quick reply.I did made some changes...
now the issue the script is only going to first disk info.. it is not taking 2nd disk in loop

Here is the updated code....the code is ending after hdisk0 "After first disk"


Code:
ssh -q node_name lspv |egrep -w 'hdisk0|hdisk1' |awk '{print $1}' |while read line; do
echo $line
outp=`ssh -q node_name bootinfo -s $line`
echo $outp
done


Code:
+ ssh -q Node_name lspv
+ egrep -w hdisk0|hdisk1
+ awk {print $1}
+ read line
+ echo hdisk0
hdisk0
+ + ssh -q Node_name bootinfo -s hdisk0
outp=140013
+ echo 140013
140013
+ read line

why it is not going to hdisk1 ?

Last edited by Don Cragun; 12-23-2017 at 03:34 PM.. Reason: Add CODE tags.
# 4  
Old 12-23-2017
Hi javedwmu,
Presumably, it doesn't go to hdisk1 because the output from the pipeline:
Code:
ssh -q node_name lspv |egrep -w 'hdisk0|hdisk1' |awk '{print $1}'

only has a line matching hdisk0 and not a line matching hdisk1. Please show us the output you get from the pipeline:
Code:
ssh -q node_name lspv |egrep -w 'hdisk0|hdisk1'

(in CODE tags).

Last edited by Don Cragun; 12-23-2017 at 05:56 PM.. Reason: Fix typo s/only a/only has a/
# 5  
Old 12-23-2017
Hi Don,
it is getting two disks.

Here is the output of the command

Code:
ssh -q Node_name lspv |egrep -w 'hdisk0|hdisk1'
hdisk0 00f8122de92xxxxx rootvg active
hdisk1 00f8122d43xxxxxx old_rootvg

Moderator's Comments:
Mod Comment Continued refusal to use CODE tags when displaying sample input, output, and code segments (as required by the forum rules you agreed to when joining this forum) may result in you being banned from this site.

And removing CODE tags that have been inserted for you by a moderator is no way to win support.

Last edited by Don Cragun; 12-23-2017 at 09:08 PM.. Reason: Re-add CODE tags again.
# 6  
Old 12-23-2017
Quote:
Originally Posted by javedwmu
Hi Don,
it is getting two disks.

Here is the output of the command

Code:
ssh -q Node_name lspv |egrep -w 'hdisk0|hdisk1'
hdisk0 00f8122de92xxxxx rootvg active
hdisk1 00f8122d43xxxxxx old_rootvg

Moderator's Comments:
Mod Comment Continued refusal to use CODE tags when displaying sample input, output, and code segments (as required by the forum rules you agreed to when joining this forum) may result in you being banned from this site.

And removing CODE tags that have been inserted for you by a moderator is no way to win support.
I don't see anything obvious that should fail in the loop you have shown us. What operating system and shell are you using?

What happens if you try the simpler script:
Code:
set -xv
ssh -q node_name lspv | grep -wo 'hdisk[01]' | while read line
do	echo $line
	outp=`ssh -q node_name bootinfo -s $line`
	echo "$outp"
done

# 7  
Old 12-24-2017
Certainly the ssh sucks from the loop input (pipe).
Even the `subshell` connects to the input.
You need ssh -n ... or </dev/null ssh ... .
This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 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

While read line loop

Based on text file: PATH:/media/hdd/Media/Video/title1 FILE:/media/cache/281662-14.jpg PATH:/media/hdd/Media/Video/title2 FILE:/media/cache/281662-15.jpg PATH:/media/hdd/Media/Video/title3 FILE:/media/cache/281662-16.jpg PATH:/media/hdd/Media/Video/title4 FILE:/media/cache/281662-17.jpg... (12 Replies)
Discussion started by: TiedCone
12 Replies

3. 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

4. Shell Programming and Scripting

Reading line in while loop

Hello Team, i have to read line by line in a while loop, and the input file has:. # The script will start cppunit test application to run unit tests. -LD_LIBRARY_PATH=$CPPUNIT_HOME/lib:\ +LD_LIBRARY_PATH=$VOBTAG/SS_UnitTest/lib:\ $VOBTAG/SS_BFD/BFDSCLI/build:\ ... (7 Replies)
Discussion started by: chandana hs
7 Replies

5. Shell Programming and Scripting

for loop with whole line using cat

Hi all, I need to create loop script to read full line and append a variable to each line. cat file I need the output like below 10.0.0.1,136 1 24 048800 id N4 No_Light 10.0.0.1,137 1 25 048900 id N4 No_Light 10.0.0.1,140 1 28 048c00 id N4 No_Light 10.0.0.1,262 1 38 048e80... (13 Replies)
Discussion started by: ranjancom2000
13 Replies

6. UNIX for Dummies Questions & Answers

One Line for loop in CRON

Hello, I'm trying to run a one line for loop from the CRON. This is the exact command /bin/bash for file in $(/bin/find /opt/local/edw_extract/logs -name "*.log"); do /bin/cat /dev/null > $file; done This will run from the command successfully. When I schedule this to run it will... (3 Replies)
Discussion started by: mhauff
3 Replies

7. Solaris

Line too long error Replace string with new line line character

I get a file which has all its content in a single row. The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file. I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Discussion started by: ducati
4 Replies

8. Shell Programming and Scripting

for loop not working - syntax error at line 6: `end of file' unexpected

I have a file called test.dat which contains a b I have written a shell script called test.sh for i in `cat test.dat` do echo $i done When i run this script using sh test.sh I get this message - test.sh: syntax error at line 6: `end of file' unexpected What is the... (3 Replies)
Discussion started by: debojyoty
3 Replies

9. Shell Programming and Scripting

how to determine last line in a while do loop

Hey guy, I have a very simple question, I have the following script, while read $test do echo "this is $test" done < /testfile What I want is instead of printing "this is $test" for each line, I want the script to print out "this is last line" for last line, how should I do it? (10 Replies)
Discussion started by: fedora
10 Replies
Login or Register to Ask a Question