[Shell] Write ping packets and arp monitoring and send text messages through shell, pingarp

Source: Internet
Author: User

[Shell] Write ping packets and arp monitoring and send text messages through shell, pingarp

  1. #! /Bin/bash
  2. NOW = "'date + % Y % m % d-% H: % M: % S '"
  3. Phonelasticsearch = 15134567893
  4. IP = 10.100.8.78
  5. GATEWAY = 10.100.30.1
  6. # Text message content with ping errors
  7. Content1 = "host is failed"
  8. # Arp host Gateway error message content
  9. Content2 = "GW is failed"
  10. # Ping Log Path
  11. LogFile = "/tmp/ping 'date" + % Y % m % d-% H-% M-% S "'. log"
  12. # Ping the other host's 100 packets and output the result to the log
  13. Ping-c100 $ IP &> $ LogFile
  14. # Use the if and else statements to determine whether the ping is successful,
  15. If ["$? "=" 0 "];
  16. Then
  17. Echo "$ NOW $ IP is OK" >>$ LogFile
  18. Else
  19. 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"
  20. Fi
  21. # Separator
  22. Echo "============================================" >>> LogFile
  23. # Arp Gateway
  24. Arp $ GATEWAY & >>$ LogFile
  25. Num = $ (cat $ LogFile | grep eth0 | wc-l)
  26. If ["$ num" = "0"];
  27. Then
  28. 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"
  29. Fi

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.