【发布时间】:2012-10-19 03:45:45
【问题描述】:
您好,我是 Expect 脚本的新手,我一直在尝试使用以下方法将 IP 地址提取到变量中:
set timeout -1
spawn $env(SHELL)
match_max 100000
send "ifconfig | grep -A 1 'eth1' | tail -1\r "
expect -re "inet addr:.* " {send "ping $expect_out(0,string)\r"}
send -- "exit\r"
expect eof
问题是它试图用 ifconfig 命令的结果进行 ping,其中包含一些字符串字符。
谁能帮我从 ifconfig 命令中提取 IP 地址并将其存储在变量中?我也一直在使用 $expect_out(buffer) ,但就是无法理解它。非常感谢您对这些方面的任何帮助。
【问题讨论】: