shell脚本编写ping包及arp的监控并发送短信功能

Phyllis ·
更新时间:2024-09-21
· 804 次阅读

下面给大家分享shell脚本编写ping包及arp的监控并发送短信功能,具体代码如下所示:

#!/bin/bash NOW="`date +%Y%m%d-%H:%M:%S`" PHONES=15134567893 IP=10.100.8.78 GATEWAY=10.100.30.1 #ping失误的短信内容 content1="host is failed" #arp主机网关失误的短信内容 content2="GW is failed" #ping日志路径 LogFile="/tmp/ping`date "+%Y%m%d-%H-%M-%S"`.log" #ping对方主机100个包并将结果输出到日志 ping -c100 $IP &> $LogFile #用if,else语句判断是否ping通, if [ "$?" == "0" ]; then echo "$NOW $IP is ok">> $LogFile else echo "$NOW $IP is down">> $LogFile &/usr/bin/curl -d "phones=$PHONES&content= $NOW $IP $content" "content-type: application/x-www-form-urlencoded;charset=UTF-8" "http://短信网关:8080" fi #分隔符 echo "================================" >> $LogFile #arp自己网关 arp $GATEWAY &>>$LogFile num=$(cat $LogFile |grep eth0|wc -l) if [ "$num" == "0" ]; then echo "$NOW $GATEWAY is down">> $LogFile &/usr/bin/curl -d "phones=$PHONES&content= $NOW $GATEWAY $content1" "content-type: application/x-www-form-urlencoded;charset=UTF-8" "http://短信网关:8080" fi

以上所述是小编给大家介绍的shell脚本编写ping包及arp的监控并发送短信,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对软件开发网网站的支持!

您可能感兴趣的文章:防止ARP攻击的shell代码使用shell脚本实现ping对应IP所对应的人名(推荐)一个shell写的ping函数ping发现掉包报警的shell代码



发送短信 监控 并发 arp ping shell脚本 shell

需要 登录 后方可回复, 如果你还没有账号请 注册新账号