我正在尝试创建一个简单的脚本来登录设备运行命令并grep输出一个单词。
到目前为止我已经
了!/bin/bash
echo ""
echo -n "Number: "
read number
echo ""
if [ "$number" = "1" ]; then
/usr/bin/expect <<EOC
set timeout 20
spawn telnet 1.1.1.1
expect "Password"
send "admin\r"
expect "Command->"
send "Status\r"
expect "Commmand->"
send "exit\r"
EOC
fi
当我运行脚本时,输出以下内容
Number: 1
spawn telnet 1.1.1.1
Trying 1.1.1.1...
Connected to 1.1.1.1.
Escape character is '^]'.
Telnet command shell
Please input username and password!
Command->admin
Username and password is ok!
Type 'help' and return for help
Command->Status
Port Status:
Port1=Yes
Port2=No
Port3=Yes
Port4=No
我希望能够做的是让telnet会话在后台运行并且只返回'Number'的值,即
Number: 1
Yes
答案 0 :(得分:0)
为了解决这个问题,我只是将所有输出发送到一个文件,然后将所需的信息用于处理。