Capture output from expect script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Capture output from expect script
# 1  
Old 07-27-2016
Capture output from expect script

Hi

I am new to Expect scripting. I have to connect to a remote server and capture the output. Here I need output of " send "list registered\r"" to be stored in a file. but after execution, /tmp/capture.txt is of 0 byte

Code:
#!/usr/bin/expect
spawn ssh abc@10.10.10.10 -p 5022
        expect "Password:"
        send "xyz123\r"
        send "W2KTT\r"
        send "list registered\r"
set var $expect_out(buffer);
set fid [open /tmp/capture.txt w]
puts $fid $var
interact

Can you please help me in fixing this
# 2  
Old 07-27-2016
Assumption your prompt contains one of (#$%)

Code:
#!/usr/bin/expect
match_max 100000
spawn ssh abc@10.10.10.10 -p 5022
        expect "Password:"
        send "xyz123\r"
        send "W2KTT\r"
        expect -re "\[#\$%]"
        send "./list registered\r"
expect -re "registered\r\n(.*)\r\n\[^\r]*\[#\$%]"
set var $expect_out(1,string)
set fid [open /tmp/capture.txt w]
puts $fid $var
interact

# 3  
Old 10-07-2016
I smell an Avaya guy!

Did anything ever come of your attempts to automate this?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect Script - Not Seeing Output from While Loop

I know something simple is missing here, "log_user 1" is set . . . after this utility opens ${InFile} (handle? for IntInFile) it needs to look for something to appear in the file ${IntInFile} and then send it to the spawned process. Then I am locking the file ${IntInFile} and clearing it out -... (0 Replies)
Discussion started by: JuanMatteo
0 Replies

2. Shell Programming and Scripting

How do I use grep output in an expect script?

Hi, I am using expect to ssh to a remote host and run a program on the remote machine which has a variable runtime. I need to wait until it finishes so I can grab the output file of this program. I am trying to use the output of grep to know when the process finishes. I am trying to capture... (0 Replies)
Discussion started by: vagabond1964
0 Replies

3. Shell Programming and Scripting

Help capturing output of expect script

match_max 500000 set timeout 30 set outcome1 {} set outcome2 {} set inputfile C:\\Users\\Administrator\\Desktop\\inputfile.txt send -i $con "\r"; expect -i $con "Desktop>" { exp_send "type $inputfile \r" } set timeout 30 expect { "Desktop>" { set outcome $expect_out(0,string);}... (3 Replies)
Discussion started by: cityprince143
3 Replies

4. Shell Programming and Scripting

Script to capture snoop output

Hi Everyone :), Need your advice as I'm new to UNIX scripting.. I'm trying to write a script to capture snoop output for 5 minutes for every hour for 24 hours. To stop snoop, I need to press Control-C to break it. This is what I got so far, but now I'm stuck! :confused: The script: # cat... (2 Replies)
Discussion started by: faraaris
2 Replies

5. Shell Programming and Scripting

Expect script without user seeing output or input

I want a shell script to call an expect script but I want the expect script to run in the background so the user is not bothered with what is going on. Is there any way to do this? ---------- Post updated at 08:23 PM ---------- Previous update was at 07:39 PM ---------- got it it was ... (1 Reply)
Discussion started by: los21282
1 Replies

6. Shell Programming and Scripting

Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting

This Expect script provides expect with a list of IP addresses to Cisco IPS sensors and commands to configure Cisco IPS sensors. The user, password, IP addresses, prompt regex, etc. have been anonymized. In general this script will log into the sensors and send commands successfully but there are... (1 Reply)
Discussion started by: genewolfe
1 Replies

7. Shell Programming and Scripting

Capture Shell Script Output To A File

Hi, I am running a shell script called dbProcess.sh which performs shutdown and startup of various Oracle instances we have.At the time of execution the script produces the following output to the command line window $./dbProcess.sh stop #### Run Details ###### Hostname : server-hop-1... (4 Replies)
Discussion started by: rajan_san
4 Replies

8. Shell Programming and Scripting

Expect - Interact output hangs when large output

Hello, I have a simple expect script I use to ssh to a workstation. I then pass control over to the user with interact. This script works fine on my HP and Mac, but on my Linux Desktop, I get a problem where the terminal hangs when ever I execute a command in the interact session that requires a... (0 Replies)
Discussion started by: natedog
0 Replies

9. Shell Programming and Scripting

script to capture certain output

Hi All, I want to create a script that capture only Date & Time, Current CPU % usage, Disk % usage, Mem % usage and Top process based on this output; Data Collected: 05/17/08 17:19:49 Refresh Interval: 600 seconds GlancePlus Started/Reset: 05/17/08 08:19:45 B3692A GlancePlus... (18 Replies)
Discussion started by: fara_aris
18 Replies

10. Shell Programming and Scripting

Capture output from interactive script

I have written a menu driven script to walk users through bringing up and down an application process. Sometimes the user tells me the script does not work taking the application down, but he can't recall seeing an error message. Is there a way to capture std out and stderr out from an... (6 Replies)
Discussion started by: MizzGail
6 Replies
Login or Register to Ask a Question