使用expect模拟telnet登录Cisco路由器,查询路由器状态
- 作者: 陆边123
- 来源: 51数据库
- 2022-08-17
#!/usr/bin/expect
set timeout 15
set ip [lindex $argv 0]
set user [lindex $argv 1]
set password [lindex $argv 2]
#模拟登录
spawn telnet $ip
expect "Username:" { send "$user\r" }
expect "Password:" { send "$password\r" }
#执行sh process cpu命令,获取CPU使用率和进程数
expect ">" { send "sh process cpu\r" }
expect eof
while 1 {
expect {
"More" { send "\ " }
"\[A-Za-z0-9]>" break
}
}
#执行sh mem | include ^Processor命令,获取内存使用情况
send "sh mem | include ^Processor\r"
expect eof
#结束查询,退出telnet
send "exit\r"
推荐阅读
