Script output as input for next command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script output as input for next command
# 8  
Old 08-07-2013
Code:
man xargs

Code:
awk '/TEST IP/&&!/n\/a/{print $NF}' file |xargs ping -n 1

# 9  
Old 08-07-2013
Hi Guys
Thanks for your responses See below which is what I put together based on the feedback.. However its not working please can you advise what im doing wrong

Code:
spawn ssh "testuser\@****************"
expect -re "testuser@************* password:"
send "********\r";
expect -re "*********>"
log_file "log.txt" ;
send "show ******************** *******\r"
expect -re "************************"
log_file;
set MYIP=$(awk '/TEST IP/ && !/n\/a/ {print $2;exit}' file)
send "******** ******* ******* ****** *** $MYIP"

the MYIP bit should pickup an ip address from the show command output (output example below)

Code:
Idle Information:
    ******: 24580
    ******: 8468
    *******: n/a
    ***********: n/a
    ****************:
      ***************: 43:24:43
      TEST IP: 100.77.16.11

This then needs to run a command using the IP shown in the TEST IP from the text output.

The error i seem to get is

Code:
can't read "2": no such variable
    while executing
"set MYIP=$(awk '/TEST IP/ && !/n\/a/ {print $2;exit}' file)"
    (file "./Lookup" line 19)

Any Help you can offre would be much appreated
# 10  
Old 08-07-2013
Try change
set MYIP=$(awk '/TEST IP/ && !/n\/a/ {print $2;exit}' file)
to
MYIP=$(awk '/TEST IP/ && !/n\/a/ {print $2;exit}' file)
# 11  
Old 08-07-2013
Reply

Tried that mate and got the below.

Code:
can't read "2": no such variable
    while executing
"MYIP=$(awk '/TEST IP/ && !/n\/a/ {print $2;exit}' file)"
    (file "./lookup" line 19)

# 12  
Old 08-07-2013
Get rid of that double quotes which is causing variable replacement.

Also use $NF instead of $2 to get IP address:
Code:
"MYIP=$(awk '/TEST IP/ && !/n\/a/ {print $2;exit}' file)"

to
Code:
MYIP=$(awk '/TEST IP/ && !/n\/a/ {print $NF;exit}' file)

# 13  
Old 08-08-2013
Reply

Hi Yoda,
Tried that and got the below
Code:
can't read "NF": no such variable
    while executing
"MYIP=$(awk '/TEST IP/ && !/n\/a/ {print $NF;exit}' file)"
    (file "./sublookup" line 19)

# 14  
Old 08-08-2013
Post the complete script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Capturing script output and input to log

Hi Is there a way that I can capture a shell script (both output and input) to a log file where I can analyze it? Thanks (6 Replies)
Discussion started by: nimo
6 Replies

2. UNIX for Dummies Questions & Answers

Using grep output as input for sed command

Hi, I would like to know if this is possible, and if so what can i do to make this work. I would like to grep a line X from fileA and then use the output to replace a word Y in fileB. grep "line X" fileA | sed -e 's/Y/X/g' > outfile this statement does not work, as i do not know how to... (7 Replies)
Discussion started by: cavanac2
7 Replies

3. Shell Programming and Scripting

Command Output to Standard Input

Hi All, How do I provide the output of a command to another command which is waiting for an input from the user ? Ex : I need to login to a device via telnet. In the script, initially I use the "read" command to get the IP Address, Username and Password of the device from the user. Now,... (1 Reply)
Discussion started by: sushant172
1 Replies

4. UNIX for Dummies Questions & Answers

Send output of grep as input of kill command

I would appreciate any help. I need to run 'ps -ef | grep 'process', get the process id and kill that process. I have got this far: - Get pid using ps -ef | awk '/process/{ print $2}' after this I'm kind of stuck.. - Use pipe to redirect the output to kill pid=ps -ef | awk '/bmserver/{... (2 Replies)
Discussion started by: foxtron
2 Replies

5. Shell Programming and Scripting

how to input the CAT command output in Shell

Hi guys... I am new to this scripting...so please forgive me if anything worng in my questions... here is my question.. I have file structure /home/oracle/<sid>/logs/bkup now i want to write a script which should grep the sid name from a file..and it should replace the <SID> with... (1 Reply)
Discussion started by: troubleurheart
1 Replies

6. UNIX for Dummies Questions & Answers

problem with output of find command being input to basename command...

Hi, I am triying to make sure that there exists only one file with the pattern abc* in path /path/. This directory is having many huge files. If there is only one file then I have to take its complete name only to use furter in my script. I am planning to do like this: if ; then... (2 Replies)
Discussion started by: new_learner
2 Replies

7. Shell Programming and Scripting

Shell script getting input from output

I have a program that can be run in terminal, when its run it either returns SSH OK or CRITICAL, how do i use the output in my script? good ./check_sh myserver SSH OK bad ./check_sh myserver CRITICAL I want to store it in a variable btw, SSH OK will give the variable $SSH=1 and if its... (1 Reply)
Discussion started by: aspect_p
1 Replies

8. Shell Programming and Scripting

Using output to input another command

Hi guys. Is it possible (I'm sure it is) to use the output of a simple 'ls' command as input of another command 'tail'. It is not really the output of the 'ls'. I have to useeach line of the output. This is the first command... ls *myFile*021308* Which it outputs many filenames. For each... (3 Replies)
Discussion started by: rodrimuino
3 Replies

9. Shell Programming and Scripting

Using Output from one command as input to another

This site has been very helpful thus far.. I thank you all in advance for sharing the knowledge. Let me get to it. I am trying to write a very small script to take away from the boredom of doing the same thing over and over. Everynow and again I have to get the hex value of a file using a... (2 Replies)
Discussion started by: BkontheShell718
2 Replies

10. Shell Programming and Scripting

Asking about shell script input output redirection

Hi, Can anyone please tell me what these lines do? ls >& outfile ls outfile 2>&1 Thanks. (1 Reply)
Discussion started by: trivektor
1 Replies
Login or Register to Ask a Question