shell 脚本监控公司外网ip 并实现邮件报警

shell 脚本监控公司外网ip 并实现邮件报警

脚本如下:

new_ip=`curl ifconfig.me`    #获取新公网ip
old_ip=`cat /root/ip`     #查看旧ip
mail_sender=1378****85@qq.com   #发件邮件邮箱
mail_user=wanbo@*****.cn    #接收收邮件邮箱
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                      #对比新旧ip 发送邮件

注:需要安装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

猜你喜欢

转载自blog.csdn.net/qq_40025218/article/details/81287839
今日推荐