admin管理员组文章数量:1566620
一、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/zjhqlmzldx/article/details/80622469
回车建(\r):https://wwwblogs/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
三、设置定时发送
涉及crontab的使用
crontab -e 加入如下代码(没太6,18点发送)
0 6,18 * * * sh ~/project/Shell_learn/send_ip.sh
参考:crontab 详细用法、定时任务 、时间规则_森林屿麓的博客-CSDN博客_crontab用法
然后启动定时服务(ubuntu上)
service cron start
版权声明:本文标题:shell登录路由器获取ip 自动通过邮件发送 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1726682241a1080796.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论