expect script regex not working -
this script failing work expected:
#!/usr/bin/expect set timeout 2 set server [lindex $argv 0] set user [lindex $argv 1] set password [lindex $argv 2] set mac [lindex $argv 3] set interface "po1" spawn ssh $user@$server expect "password:" send -- "$password\n" expect "*>" send "show mac address-table address $mac\n" # 100 1cc1.de65.441c dynamic ip,ipx,assigned,other port-channel43 expect -re { (\d+) *($mac) *(dynamic|static) *(.*) *(.*)} { set interface $expect_out(5,string) expect "*>" send "show interface $interface status\n" } send "exit\n" interact
after issuing show mac command above, output contains 1 line looks 1 commented below it. following expect -re block never hit, making time out , send exit command.
sample output: spawn ssh user@host password:
================= host login banner ================= host>show mac address-table address 1cc1.de65.441c unicast entries vlan mac address type protocols port ---------+---------------+--------+---------------------+------------------------- 100 1cc1.de65.441c dynamic ip,ipx,assigned,other port-channel43 host>exit connection host closed.
your regex not correct , inside braces substitutions won't happen. i.e. $mac
won't substituted inside braces.
expect { -re "\\d+\\s+$mac\\s+(dynamic|static)\\s+\\s+\\s+(\\s+)" { set interface $expect_out(2,string); # add further code} }
Comments
Post a Comment