SoFunction
Updated on 2025-03-10

Shell scripts to write ping packages and arp monitoring and send SMS functions

Below I will share with you the monitoring and sending SMS functions of shell script writing ping packages and arp. The specific code is as follows:

#!/bin/bash
NOW="`date +%Y%m%d-%H:%M:%S`"
PHONES=15134567893
IP=10.100.8.78
GATEWAY=10.100.30.1
#ping error message contentcontent1="host is failed"
#arp host gateway error message contentcontent2="GW is failed"
#ping log pathLogFile="/tmp/ping`date "+%Y%m%d-%H-%M-%S"`.log"
#ping 100 packages on the other party's host and output the results to the logping -c100 $IP &> $LogFile
# Use if and else statement to determine whether ping is clear,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://SMS Gateway: 8080"fi
#delimiterecho "================================" >> $LogFile
#arp own gatewayarp $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://SMS Gateway: 8080"fi

The above is the monitoring of the shell script writing ping package and arp introduced by the editor and sending text messages. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!