如何在bash中保存输出expect
我正在尝试制作一个脚本,以保存cisco中命令显示版本的输出 我需要建立一个连接到一个服务器的ssh连接,然后我与设备连接 在out.txt文件中,我有第一个连接的输出,ssh连接,但我不知道如何保存show版本的输出如何在bash中保存输出expect,bash,expect,cisco,Bash,Expect,Cisco,我正在尝试制作一个脚本,以保存cisco中命令显示版本的输出 我需要建立一个连接到一个服务器的ssh连接,然后我与设备连接 在out.txt文件中,我有第一个连接的输出,ssh连接,但我不知道如何保存show版本的输出 #!/usr/bin/expect -f #!/bin/sh spawn ssh -l user x.x.x.x expect "login as:" expect "password:" send "password\r" expect "$\r" send "telnet n
#!/usr/bin/expect -f
#!/bin/sh
spawn ssh -l user x.x.x.x
expect "login as:"
expect "password:"
send "password\r"
expect "$\r"
send "telnet nemonic\r"
expect "$\r"
expect "login:"
send "user\r"
expect "password:"
send "password\r"
expect "*>"
send "terminal length 0\r"
send "show version \r"
expect "*>"
set results $expect_out(buffer)
set config [open out.txt w]
puts $config $results
close $config
send "exit\r"
expect eof
send "\r"
send "exit\r"
你能帮我吗
致以最诚挚的问候我与
log_file -noappend status.txt
命令后显示版本
#!/usr/bin/expect -f
#!/bin/sh
spawn ssh -l user x.x.x.x
expect "login as:"
expect "password:"
send "password\r"
expect "$\r"
send "telnet nemonic\r"
expect "$\r"
expect "login:"
send "user\r"
expect "password:"
send "password\r"
expect "*>"
send "terminal length 0\r"
send "show version \r"
expect "*>"
set results $expect_out(buffer)
set config [open out.txt w]
puts $config $results
close $config
send "exit\r"
expect eof
send "\r"
send "exit\r"
谢谢你和致以最良好的问候你不能有两个shebang。^^尽管如此,我认为expect会将第二行解释为评论&忽略它。整个脚本是纯expect脚本。expect工作正常,问题是输出,只需保存第一个连接,但是如果你告诉我,如何在一行中实现它,我做到了,谢谢@anishsane