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
# 15  
Old 08-08-2013
You need to do the parsing/extraction natively within the expect script. The solutions given so far require a spawning of 'awk' which I'm not sure if expect allows.
I'm no expect guru, but maybe other will help.
# 16  
Old 08-08-2013
Full Script

Code:
#!/usr/bin/expect

set timeout 20

set ms [lindex $argv 0]

log_user 1

#Testnode

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

# 17  
Old 08-09-2013
Reply

Can anyone add to the above ?

Any help is appreaciated as im stuck!
# 18  
Old 08-16-2013
Study tk and tcl tutorials online, as expect is made from, and scripted with, these languages.

Alternatively, I have written expect-like scripts that mostly ran in the parentheses piped to stdin, examining the log file where stdout and stderr are being written. This rescues me from learning another script langage. It does have minor problems getting control of /dev/tty if that is where passwords and such are read from. For instance, a primitive remote smtp/esmtp email client from telnet:
Code:
$ (
  >>my_mailer_log
 
  <script that examines log file my_mailer_log for progress and generates input>
 ) | telnet mailhost 25 > my_mailer_log 2>&1

# 19  
Old 08-18-2013
Hi Guys,
Just to follow up really, I managed to complete what i needed by using a perl script which then called an expect script in order to login to the relivant elements and run the commands required.

Thanks to everyone who helped.
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