使用expect模拟telnet登录Cisco路由器,查询路由器状态

2015-06-19 0 905
使用expect模拟telnet登录Cisco路由器,查询路由器状态
#!/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"

遇见资源网 shell 使用expect模拟telnet登录Cisco路由器,查询路由器状态 http://www.ox520.com/17016.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务