Linux 如何在expect脚本中捕获变量
我试图在远程串行连接上捕获主机的IP,以便稍后可以通过ssh连接到主机。但是我真的不明白expect是如何工作的,这就是我到目前为止想到的 我尝试使用发布的代码,但似乎无法将var设置为所需的值,要么是空的,要么是命令本身Linux 如何在expect脚本中捕获变量,linux,expect,Linux,Expect,我试图在远程串行连接上捕获主机的IP,以便稍后可以通过ssh连接到主机。但是我真的不明白expect是如何工作的,这就是我到目前为止想到的 我尝试使用发布的代码,但似乎无法将var设置为所需的值,要么是空的,要么是命令本身 #!/usr/bin/expect -f spawn serialconn expect -re "#" send "ip addr list eth0 |grep -m1 inet |cut -d' ' -f6|cut -d/ -f1\r" set ip {} expe
#!/usr/bin/expect -f
spawn serialconn
expect -re "#"
send "ip addr list eth0 |grep -m1 inet |cut -d' ' -f6|cut -d/ -f1\r"
set ip {}
expect {
-regexp {..#} {
append ip "${ip}$expect_out(0,string)"
exp_continue
}
}
puts $ip
spawn serialconn finished
expect -re "%"
spawn sudo ssh $ip
我想问的问题是我的代码中的-regexp{..}是什么(我找到了代码并重新修改了一点)。如果有人能解释整个过程,那就太好了。谢谢
我希望将IP保存到变量中,以便我可以将sudo ssh保存到主机中