Shell writes ping packets and ARP monitoring and sends text messages through the shell

Source: Internet
Author: User

  1. #!/bin/bash
  2. now= "' Date +%y%m%d-%h:%m:%s '"
  3. phones=15134567893
  4. ip=10.100.8.78
  5. gateway=10.100.30.1
  6. #ping失误的短信内容
  7. Content1= "host is failed"
  8. #arp主机网关失误的短信内容
  9. Content2= "GW is failed"
  10. #ping日志路径
  11. logfile= '/tmp/ping ' Date "+%y%m%d-%h-%m-%s" '. Log '
  12. #ping对方主机100个包并将结果输出到日志
  13. ping-c100 $IP &> $LogFile
  14. #用if, the Else statement determines whether the ping pass,
  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-ty Pe:application/x-www-form-urlencoded;charset=utf-8 "" http:/SMS Gateway 8080 "
  20. Fi
  21. #分隔符
  22. echo "================================" >> $LogFile
  23. #arp自己网关
  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 $content 1" "Content-type:application/x-www-form-urlencoded;charset=utf-8" "http:/SMS Gateway 8080"
  29. Fi

Shell writes ping packets and ARP monitoring and sends text messages through the shell

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.