shell 脚本监控公司外网ip 并实现邮件报警
发表于:2021-11-09 |
#!/bin/bash
new_ip=`curl ifconfig.me`    #获取新公网ip
old_ip=`cat /root/ip`     #查看旧ip
mail_sender=1776803208@qq.com   #发件邮件邮箱

   mail_user=xxxxx   #接收收邮件邮箱
mail_subject=IP_CHANGED #邮件主题

if [ ! $new_ip == $old_ip ]
then
echo  $new_ip > /root/ip
echo "ip has changed, the new ip is $new_ip !!! "|mail -s "$mail_subject" -S from=$mail_sender "$mail_user"
fi                    

注:需要安装mailx 按脚本新建对应得ip文件 –> /root/ip
配置定时任务:
*/5 * * * * /root/ip.sh >/dev/null 2>&1

其他获取新公网ip方法:
curl icanhazip.com
curl ifconfig.me
curl ident.me
curl http://ip.3322.net
curl whatismyip.akamai.com
curl http://members.3322.org/dyndns/getip

上一篇:
docker 搭建redis可视化工具treenms
下一篇:
ubuntu 安装发送邮件 heirloom-mailx