Sponsored Content
Top Forums Shell Programming and Scripting Parsing expect_out using regex in expect script Post 302745177 by ashy_g on Monday 17th of December 2012 02:04:26 AM
Old 12-17-2012
Thanks for the reply Chubler_XL, but it still doesnot solve my problem

So, essentailly, my script now looks something like this
--------------------------------------------------------------
Code:
#!/usr/bin/expect
spawn su admin
expect "abc>"
send "en\r"
expect "abc#"
sleep 1
send "show traffic \r"
send " "


set values $expect_out(buffer)

set found [regexp { \| ([0-9]+)\r\n.* \| ([0-9]+)\r\n.* \| ([0-9]+)\r\n.* \| ([0-9]+)} $values match px vpx by vby]
if {$found == 1} {
    puts "px is $px"
    puts "vpx is $vpx"
    puts "by is $by"
    puts "vby is $vby"
} else {
    puts "No match found!"
}

interact

---------------------------------------------------------


And the output of the command , "show traffic" is

Code:
abc#show  traffic

[ SLOT : 1 ]
--------------------------------------------------------------
                      Traffic Statistics
--------------------------------------------------------------
Input  Packets Rx                             |               29262
Input Module Valid Packets Rx             |               29262
Rx Packets                               |                 104
Tx Packets                               |                   0

and my script does not store the variables correctly :-(

Thanks,
Ashish

Last edited by Franklin52; 12-17-2012 at 07:00 AM.. Reason: fixed code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect: Parsing/evaluating lines of numbers

There *has* to be an elegant way to do this in Expect... I have a command that returns lines of numbers. Like: prompt% mycommand --loop=5 9 4956 4951 4951 4956 9 4960 4951 4951 4956 9 4956 4951 4951 4956 9 4956 4951 4951 4956 9 4956 4951 4951 4956 prompt% All numbers must be... (0 Replies)
Discussion started by: kajkaj
0 Replies

2. Shell Programming and Scripting

strange expect script behavior, or am i misunderstanding expect scripting?

Hello to all...this is my first post (so please go easy). :) I feel pretty solid at expect scripting, but I'm running into an issue that I'm not able to wrap my head around. I wrote a script that is a little advanced for logging into a remote Linux machine and changing text in a file using sed.... (2 Replies)
Discussion started by: v1k0d3n
2 Replies

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

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

5. Shell Programming and Scripting

Expect and regex

I'm using Expect to execute a command on a router and return the output to a file. The output is a list. At the end of the list there's a statement that reads, "Found 165 active connections" (Where "165" could be any number between 0 and 2000.) I'm familiar with using Expect to return data from... (2 Replies)
Discussion started by: professorx
2 Replies

6. Shell Programming and Scripting

expect_out buffer no such variable running script background

I am trying to use send and receive using expect. the expect_out(buffer) is working fine while it is running it as foreground. But the same script when it is ran as background, the expect_out(buffer) errored out. Is there any factor influence when we run script in foreground and in background? ... (0 Replies)
Discussion started by: shellscripter
0 Replies

7. Solaris

Help with parsing regex in tripwire for Solaris 10 dfstab

Help with parsing regex in tripwire: the rule is" This test verifies that exported file systems do not have the "root=<host>" option specified." regex that does not work is : ^.*-o+(?=root=\S+|\S+,root=\S+).* the dfstab looks like this : # cat /etc/dfs/dfstab # Place... (1 Reply)
Discussion started by: bathija12
1 Replies

8. Solaris

Help with parsing regex in tripwire for Solaris 10 dfstab FQDN

Help with parsing regex in tripwire: the rule is" This test verifies that all exported file systems found in /etc/exports specify a fully qualified domain name containing "thecss.com" or a NIS netgroup.." regex that does not work is : ... (1 Reply)
Discussion started by: bathija12
1 Replies

9. Solaris

Help with parsing regex in tripwire

We have regex that we use to parse compliance policies in tripwire. can you please help to correct the regex : policy is "Verify That Exported File Systems Specify the ro (read-only) Option" the regex is ^.*-o+(?!ro+|ro\S+|\S+,ro\S+|\S+,ro+).*$ this does not work. how do we fix it ? ... (4 Replies)
Discussion started by: bathija12
4 Replies

10. UNIX for Beginners Questions & Answers

Help with understanding this regex in a Perl script parsing a 'complex' string

Hi, I need some guidance with understanding this Perl script below. I am not the author of the script and the author has not leave any documentation. I supposed it is meant to be 'easy' if you're a Perl or regex guru. I am having problem understanding what regex to use :confused: The script does... (3 Replies)
Discussion started by: newbie_01
3 Replies
TRACETOPENDS(1) 						   User Commands						   TRACETOPENDS(1)

NAME
tracetopends - reports the endpoints that are responsible for the most traffic in a trace SYNOPSIS
tracetopends [ -f bpf ] [ -A addrtype ] [ -s ] [ -d ] [ -b ] [ -a ] [ -p ] [ -n topcount ] inputuri [inputuri ...] DESCRIPTION
tracetopends reports the number of bytes and packets sent and received by the busiest endpoints observed in the input trace(s). -f bpf filter Output only packets that match tcpdump style bpf filter. -n top count Report the top N endpoints (defaults to 10). -A address type Specifies how an endpoint should be defined. Suitable options are "mac", "v4" and "v6" which will report endpoint stats for each observed MAC address, IPv4 address and IPv6 address respectively. -s Sort endpoints based on the amount of outgoing traffic (will cancel any previous -d option. This is on by default. -d Sort endpoints based on the amount of incoming traffic (will cancel any previous -s option. -b Sort endpoints based on the amount of IP traffic (will cancel any previous -a or -p options. This is on by default. -a Sort endpoints based on the amount of application layer traffic (will cancel any previous -b or -p options. -p Sort endpoints based on the amount of packets (will cancel any previous -b or -a options. OUTPUT
Output is written to stdout in columns separated by blank space. The columns are (in order): * Endpoint address * Time last observed * Packets originating from the endpoint * Bytes originating from the endpoint (IP header onwards) * Payload originating from the endpoint (post transport header) * Packets sent to the endpoint * Bytes sent to the endpoint (IP header onwards) * Payload sent to the endpoint (post transport header) EXAMPLES
Find the IPv4 addresses that are sending the most traffic. tracetopends -A v4 -b -s erf:trace.erf.gz LINKS
More details about tracetopends (and libtrace) can be found at http://www.wand.net.nz/trac/libtrace/wiki/UserDocumentation SEE ALSO
libtrace(3), tracemerge(1), tracefilter(1), traceconvert(1), tracesplit_dir(1), tracereport(1), tracertstats(1), tracestats(1), tracepkt- dump(1), traceanon(1), tracesummary(1), tracereplay(1), tracediff(1), traceends(1) AUTHORS
Shane Alcock <salcock@cs.waikato.ac.nz> tracetopends (libtrace) September 2011 TRACETOPENDS(1)
All times are GMT -4. The time now is 05:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy