Sponsored Content
Full Discussion: Expect_out help!!!
Top Forums Shell Programming and Scripting Expect_out help!!! Post 302878862 by in2nix4life on Monday 9th of December 2013 09:36:05 AM
Old 12-09-2013
Here's an example of the way that I've done it in the past. Hope this helps.

Code:
#!/usr/bin/expect -f
#
# example of executing a command with expect
# and retrieving an exit\return code
#

# set credentials
set u ""
set p ""

# set hostname
set h ""

# set command to run
set cmd "CMD 2>/dev/null"

# capture the return code from the command
set retval "echo 'Return Code: '$?"

# spawn the ssh connection, run the command,
# and retrieve the return code
spawn ssh $u@$h "$cmd;$retval"
expect "?assword*"
send -- "$p\r"
send -- "\r"
expect -re {Return Code: (\d+)}
set retval $expect_out(1,string)
expect eof

# process the return code
if {$retval != 0} {
    puts stderr "Fail"
} else {
    puts stderr "Pass"
}

7a8b1a878d0ef333911b000d7c6858c8
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with expect expect_out

This is my simple expect scritpt: #!/usr/bin/expect -f match_max 100000 set timeout -1 spawn telnet $IP expect "#" send -- "shell\r" expect "*Ready*" send -- "init\r" expect "*Ready*" send -- "readsensor \r" expect -- "*" <<< Output of this is a 2 digit number set val... (5 Replies)
Discussion started by: expect_user
5 Replies

2. Shell Programming and Scripting

expect_out(buffer) empty

I have only some info into my buffer, but after a rssi command I see the folowing lines expected into buffer but not present : rssi=-106 rssi=-109 I see in my buffer only the first part of the output, here you are a part of script : #!/usr/bin/expect -f #global expect_out match_max 10000000... (1 Reply)
Discussion started by: ugobale
1 Replies

3. Shell Programming and Scripting

Problems with expect_out command

expect "#" send "terminal-length 0\r" expect "#" send "show mp cpu\r" expect "#" send "show mp memory\r" expect "#" while {1} { expect "#" send "clear counters\r" sleep 30 ... (0 Replies)
Discussion started by: roh_20022002
0 Replies

4. Programming

[SOLVED] Flushing expect_out(buffer) inside a loop

Greetings, Having an issue with the expect_out(buffer). in a foreach loop through some switches I am grabbing some arp table information and writing it out to output files (1 each for each switch looped through). The first iteration works fine. the second iteration of the loop writes the... (0 Replies)
Discussion started by: SuperSix4
0 Replies

5. Shell Programming and Scripting

Parsing expect_out using regex in expect script

Hi, I am trying to write an expect script. Being a newbie in expect, maybee this is a silly doubt but i am stuck here. So essentially , i want the o/p of one router command to be captured . Its something like this Stats Input Rx : 1234 Input Bytes : 3456 My expect script looks ... (5 Replies)
Discussion started by: ashy_g
5 Replies

6. Shell Programming and Scripting

Expect_out(buffer) works but it doesn't get all lines

Hello "expect" experts I am new at Expect. I have searched for a little while how to capture multiple lines with Expect and I am almost succeeded on that but I don't get all the lines of a command's output that the script executes on a server. Here is how my script works in a nutshell - ... (6 Replies)
Discussion started by: capacho6666
6 Replies

7. Programming

Flushing expect_out(buffer)

Can some one tell me how to flush expect_out(buffer)? below is my code expect -re {.*} {} expect "swpackages>*" send -i $con "trial.bat \r" set outcome $expect_out(buffer) expect "*continue*" set prevreport $expect_out(buffer) send "\r \r"; problem is :- I am getting "pre" stuffs... (0 Replies)
Discussion started by: cityprince143
0 Replies

8. Shell Programming and Scripting

Jumbled output in expect_out(buffer)

I have a code like this : set ipv6_acl_max_chars test_acl_max_chars123456a789%s%d2345678ww134rt789qa23456789012345%c89012%a56789012x4r67890test_acl_max_chars1234567890.01234aabcdob34567aBC0 spawn telnet $myip expect "Login:" { send "admin\r" } expect "Password:" {send "admin\r" }... (0 Replies)
Discussion started by: ylucki
0 Replies

9. Shell Programming and Scripting

Trying to parse expect_out(buffer)

trying to telnet to a device, list the files, and delete them. I can get the script to telnet and log in OK, and even issue the command to list out the files. I can't figure out how to parse the expect_out(buffer) and extract the file name for use in the delete command. the files list out like... (4 Replies)
Discussion started by: imatinkerer
4 Replies

10. Shell Programming and Scripting

Save an specific part of a expect_out in a variable

I have a expect file like this #!/opt/tools/unsupported/expect-5.39/bin/expect spawn ssh -l user ip expect_after eof {exit 0} set timeout 10 log_file /report.txt expect "Password:" { send "pasword\r" } expect "$ " { send "date\r" } expect "$ " { send "readlink /somelink\r" } set... (7 Replies)
Discussion started by: bebehnaz
7 Replies
PAPI_detach(3)							       PAPI							    PAPI_detach(3)

NAME
PAPI_detach - Detach PAPI event set from previously specified thread id and restore to executing thread. SYNOPSIS
Detailed Description @par C Interface: int PAPI_detach( int EventSet, unsigned long tid ); PAPI_detach is a wrapper function that calls PAPI_set_opt to allow PAPI to monitor performance counts on a thread other than the one currently executing. This is sometimes referred to as third party monitoring. PAPI_attach connects the specified EventSet to the specifed thread; PAPI_detach breaks that connection and restores the EventSet to the original executing thread. @param EventSet An integer handle for a PAPI EventSet as created by PAPI_create_eventset. @param tid A thread id as obtained from, for example, PAPI_list_threads or PAPI_thread_id. @retval PAPI_ECMP This feature is unsupported on this component. @retval PAPI_EINVAL One or more of the arguments is invalid. @retval PAPI_ENOEVST The event set specified does not exist. @retval PAPI_EISRUN The event set is currently counting events. @par Examples: * int EventSet = PAPI_NULL; * unsigned long pid; * pid = fork( ); * if ( pid <= 0 ) * exit( 1 ); * if ( PAPI_create_eventset( &EventSet ) != PAPI_OK ) * exit( 1 ); * // Add Total Instructions Executed to our EventSet * if ( PAPI_add_event( EventSet, PAPI_TOT_INS ) != PAPI_OK ) * exit( 1 ); * // Attach this EventSet to the forked process * if ( PAPI_attach( EventSet, pid ) != PAPI_OK ) * exit( 1 ); * See Also: PAPI_set_opt PAPI_list_threads PAPI_thread_id PAPI_thread_init Author Generated automatically by Doxygen for PAPI from the source code. Version 5.2.0.0 Tue Jun 17 2014 PAPI_detach(3)
All times are GMT -4. The time now is 08:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy