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

本文介绍了一个使用shell脚本监控公司外网IP,并在IP变化时通过邮件报警的方法。脚本利用curl命令获取公网IP,通过比较新旧IP来触发邮件通知。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

免费领取满减阿里云红包阿里云红包
脚本如下:

#!/bin/bash
#write by wanbo at 2018-10
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值