- 论坛徽章:
- 1
|
有没有脚本高手,给我演示如何自动监控路由器的ip accounting
你推半天我猜大概也沒有什麼解答 ~
如果你愛用 shell , expect 這個東西你要弄熟,因主要你登入 router 後
會有許多互動性的操作,我只給你一個固定的範本,其他你就 man expect
較快,會用了,你會愛上他的...但別愛上我
- #!/usr/bin/expect
- spawn telnet IP # 連到那個 IP
- expect Password: # Cisco 會出垷這個提示符號,你要去套這個 String
- send "Passwd_here"\r" # expect 看到這個符號後送出 passwd
- expect r2620>; # 這是我的例子,你登入後看到什麼對應改
- send "en\r" # 送出 enable
- expect Password: # 看到 Password: 符號後送出
- send "enable_password_here\r" # 你的 en passwd
- expect r2620# # 同理,看到 這個 prompt
- send "show ip account \r" # 送出 指令
- send " \r" #這裏我不想弄的太?#125;雜,就一直丟空白鍵...你自己看看丟幾個較合適
- expect r2620# # 提示符
- send "quit\r\r" # 退出
- send "\r"
复制代码
這些結果都是標準輸出的 (stdout) , 所以你可以存出如 0755 mode
./cisco.account | sort |uniq |xxx| ...
expect 很簡單,但常人都想的太難,你可以再把這個 sample 做得更好
例如,更新 access-list ..,備份 running-config ...等
至於你要做 sort/uniq 等你自己去想了,我只秀你不了解的地方 |
|