LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Using regular expression in expect script (https://www.linuxquestions.org/questions/programming-9/using-regular-expression-in-expect-script-665955/)

nik1984 08-28-2008 01:01 AM

Using regular expression in expect script
 
using regular expression in expect scripts

i wrote expect script that will check string out put of "show clock" command but i want to validate this using regular expression...how i can do validation using expect script & store output from expect command.

==================================
sample expect script


#!/usr/bin/expect -f

set timeout -1
spawn ./Nikcli.sh
expect -exact "\rNik> [m"
set date_var [exec date]

send -- "show clock\r"
expect -exact "$date_var\r
\rNik> "

send -- ""
expect eof

=============================


-Thanks in advance

matthewg42 08-28-2008 06:25 AM

Use the -indices flag to the expect command, and the -re pattern type option. Then the expect_out variable will be set after a match is found, and sub-expressions in your RE will be available.

From the expect manual page:
Quote:

If a process produced the output "abbbcabkkkka\n", the result of:
Code:

expect -indices -re "b(b*).*(k+)"
is as if the following statements had executed:
Code:

set expect_out(0,start) 1
set expect_out(0,end) 10
set expect_out(0,string) bbbcabkkkk
set expect_out(1,start) 2
set expect_out(1,end) 3
set expect_out(1,string) bb
set expect_out(2,start) 10
set expect_out(2,end) 10
set expect_out(2,string) k
set expect_out(buffer) abbbcabkkkk




All times are GMT -5. The time now is 03:29 PM.