[Shell] Write ping packets and arp monitoring and send text messages through shell, pingarp
- #! /Bin/bash
- NOW = "'date + % Y % m % d-% H: % M: % S '"
- Phonelasticsearch = 15134567893
- IP = 10.100.8.78
- GATEWAY = 10.100.30.1
- # Text message content with ping errors
- Content1 = "host is failed"
- # Arp host Gateway error message content
- Content2 = "GW is failed"
- # Ping Log Path
- LogFile = "/tmp/ping 'date" + % Y % m % d-% H-% M-% S "'. log"
- # Ping the other host's 100 packets and output the result to the log
- Ping-c100 $ IP &> $ LogFile
- # Use the if and else statements to determine whether the ping is successful,
- 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
- # Separator
- Echo "============================================" >>> LogFile
- # Arp Gateway
- 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: // SMS Gateway: 8080"
- Fi