一、shell登录路由器
涉及telnet登录路由器ip,expect进行交互式操作进行登录。
vim get_route_ip.sh 内容如下:
#! /usr/bin/expect
spawn telnet 192.168.0.1
expect "Username:"
send "Admin\r"
expect "Password:"
send "123456\r"
expect "*#"
send "show ip route\r"
expect eof
exit
END
参考:expect用法:https://blog.csdn.net/zjhqlmzldx/article/details/80622469
回车建(\r):https://www.cnblogs.com/liutaolt/p/15293535.html
二、自动通过邮件发送信息
1。首先根据下面链接进行配置
参考:发送邮件ubuntu中使用shell发送邮件的方法_weixin_30784945的博客-CSDN博客
2。创建shell脚本
vim send_ip.sh (这里用的网易163邮箱)
#! /bin/bash
MY_PATH=/home/xxxx/xxxx #该文件的绝对路径
${MY_PATH}/get_route_ip.sh | mutt -s "ip" you_email@163.com
三、设置定时发送
涉及crontab的使用
crontab -e 加入如下代码(没太6,18点发送)
0 6,18 * * * sh ~/project/Shell_learn/send_ip.sh
参考:crontab 详细用法、定时任务 、时间规则_森林屿麓的博客-CSDN博客_crontab用法
然后启动定时服务(ubuntu上)
service cron start