หน้าเว็บ

วันพุธที่ 15 สิงหาคม พ.ศ. 2561

Ubuntu :: Ubuntu set track ping to other host. For check online or down.

Ubuntu :: Ubuntu set track ping to other host. For check online or down.
Use php and bash shell run crontab. On Ubuntu 18.04
1. Install software.
  1. sudo apt-get install apache2

  1. sudo apt install php libapache2-mod-php

  1. sudo apt-get install ssmtp mailutils mpack


2. Set timezone.
List
  1. timedatectl list-timezones

Set
  1. timedatectl set-timezone Asia/Bangkok


3. Create file php.
  1. nano /var/www/check-sonoff.php

insert code
  1.  
  2. <?php
  3. $strDateTime = date("Y-m-d H:i:s");
  4.  
  5. $strToPost = "\nFrom Home Assistan : {$strDateTime} \n";
  6. $ret = mail("komkid@gmail.com,suwit.jph@gmail.com,seksan.kamt56@gmail.com", "Internet Test Speed is low. Please Check Internet Connection.", $strToPost, "From: Proxy Server\n");$
  7. //$ret = mail("suwit.jph@gmail.com", "Can't connect sonoff Garden. Please Check WIFI Or Sonoff.", $strToPost, "From: Home Assistan \n");
  8.  
  9. ?>


4. Config send mail.
backup original file.
  1. cp /etc/ssmtp/ssmtp.conf ssmtp.conf.backup
  1. nano /etc/ssmtp/ssmtp.conf

replace all code.
  1. #
  2. # Config file for sSMTP sendmail
  3. #
  4. # The person who gets all mail for userids < 1000
  5. # Make this empty to disable rewriting.
  6. #root=postmaster
  7. root=scivalve.suwit@gmail.com
  8.  
  9. # The place where the mail goes. The actual machine name is required no
  10. # MX records are consulted. Commonly mailhosts are named mail.domain.com
  11. mailhub=mail
  12. mailhub=smtp.gmail.com:587
  13.  
  14. # Where will the mail seem to come from?
  15. #rewriteDomain=
  16.  
  17. # The full hostname
  18. #hostname=scivalve.suwit@gmail.com
  19. hostname=localhost
  20.  
  21. # Are users allowed to set their own From: address?
  22. # YES - Allow the user to specify their own From: address
  23. # NO - Use the system generated From: address
  24. #FromLineOverride=YES
  25.  
  26. AuthUser=MAIL GMAIL
  27. AuthPass=PASSWORD
  28. useSTARTTLS=YES
  29.  
  30. TLS_CA_File=/etc/ssl/certs/ca-certificates.crt


5. Test send mail.
  1. /usr/bin/php /var/www/check-sonoff.php


6. Create file for check ping to other server.
  1. nano check-sonoff.sh

insert code.
  1. #!/bin/bash
  2. SERVERIP=192.168.0.210
  3.  
  4. ping -c 3 $SERVERIP > /dev/null 2>&1
  5. if [ $? -ne 0 ]
  6. then
  7.    # Call php file send mail here:
  8.    /usr/bin/php /var/www/check-sonoff.php
  9. fi


7. Test sell.
  1. bash check-sonoff.sh


8. Set crontab. run bash file.
  1. #Check Ping Sonoff Every 1 Hours
  2. 0 8-18 * * 1-6 bash /check-sonoff.sh


https://unix.stackexchange.com/questions/56340/bash-script-to-detect-when-my-server-is-down-or-offline
https://askubuntu.com/questions/3375/how-to-change-time-zone-settings-from-the-command-line

ไม่มีความคิดเห็น:

แสดงความคิดเห็น