如果有人可以帮助我使用这个基本的期望脚本,因为它会让我作为网络工程师的生活更轻松。我不是一个好的 Linux 用户,因为我不经常使用它,但我需要能够制作一个基本的期望脚本.您可以在我的简单示例下方看到仅使用“sh ip int br”命令。我将使用相同的逻辑进入配置模式以使用其他命令,但我最大的问题是我无法登录到我的路由器。我非常感谢您的帮助。
1.我已经制作了你可以在下面看到的脚本
#!/usr/bin/expect
set username elio
set password hgkjtjwowq
set host 172.16.12.254
spawn telnet $host
expect "login:"
send "$username\r"
expect "Password:"
send "$password\r"
expect "Nexus1#"
send "sh ip int br\r"
expect "Nexus1#"
send "exi\r"
expect eof
2.我检查了我的脚本在哪里
elio@mabu-199:~$ whereis expect
expect: /usr/bin/expect /usr/bin/X11/expect /usr/share/man/man1/expect.1.gz
3.你可以看到当我运行脚本时我收到以下信息
elio@mabu-199:~$ ./testscript.exp
./testscript.exp: line 8: spawn: command not found
couldn't read file "login:": no such file or directory
./testscript.exp: line 10: send: command not found
couldn't read file "Password:": no such file or directory
./testscript.exp: line 12: send: command not found
couldn't read file "Nexus1#": no such file or directory
./testscript.exp: line 14: send: command not found
couldn't read file "Nexus1#": no such file or directory
./testscript.exp: line 16: send: command not found
couldn't read file "eof": no such file or directory
感谢您的帮助。在此先感谢