我尝试使用期望脚本备份 Linkproof 设备,但遇到了一些麻烦。这是我的第一个脚本,我已经达到了我的极限;)
#!/usr/bin/expect
spawn ssh @IPADDRESS
expect "username:"
# Send the username, and then wait for a password prompt.
send "@username\r"
expect "password:"
# Send the password, and then wait for a shell prompt.
send "@password\r"
expect "#"
# Send the prebuilt command, and then wait for another shell prompt.
send "system config immediate\r"
#Send space to pass the pause
expect -re "^ *--More--\[^\n\r]*"
send ""
expect -re "^ *--More--\[^\n\r]*"
send ""
expect -re "^ *--More--\[^\n\r]*"
send ""
# Capture the results of the command into a variable. This can be displayed, or written to disk.
sleep 10
expect -re .*
set results $expect_out(buffer)
# Copy buffer in a file
set config [open linkproof.txt w]
puts $config $results
close $config
# Exit the session.
expect "#"
send "logout\r"
expect eof
输出文件的内容:
无法确定主机“@IP (XXX.XXX.XXX.XXX)”的真实性。
RSA 密钥指纹为 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX。
您确定要继续连接(是/否)?@用户名
请输入“是”或“否”:@password
请输入“是”或“否”:系统配置立即
请输入“是”或“否”:
如您所见,命令的结果不在文件中。请你帮我理解为什么?谢谢你的帮助。
罗穆尔德