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.
2. Set timezone.
List
Set
3. Create file php.
insert code
4. Config send mail.
backup original file.
replace all code.
5. Test send mail.
6. Create file for check ping to other server.
insert code.
7. Test sell.
8. Set crontab. run bash file.
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
Use php and bash shell run crontab. On Ubuntu 18.04
1. Install software.
- sudo apt-get install apache2
- sudo apt install php libapache2-mod-php
- sudo apt-get install ssmtp mailutils mpack
2. Set timezone.
List
- timedatectl list-timezones
Set
- timedatectl set-timezone Asia/Bangkok
3. Create file php.
- nano /var/www/check-sonoff.php
insert code
- <?php
- $strDateTime = date("Y-m-d H:i:s");
- $strToPost = "\nFrom Home Assistan : {$strDateTime} \n";
- $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");$
- //$ret = mail("suwit.jph@gmail.com", "Can't connect sonoff Garden. Please Check WIFI Or Sonoff.", $strToPost, "From: Home Assistan \n");
- ?>
4. Config send mail.
backup original file.
- cp /etc/ssmtp/ssmtp.conf ssmtp.conf.backup
- nano /etc/ssmtp/ssmtp.conf
replace all code.
- #
- # Config file for sSMTP sendmail
- #
- # The person who gets all mail for userids < 1000
- # Make this empty to disable rewriting.
- #root=postmaster
- root=scivalve.suwit@gmail.com
- # The place where the mail goes. The actual machine name is required no
- # MX records are consulted. Commonly mailhosts are named mail.domain.com
- mailhub=mail
- mailhub=smtp.gmail.com:587
- # Where will the mail seem to come from?
- #rewriteDomain=
- # The full hostname
- #hostname=scivalve.suwit@gmail.com
- hostname=localhost
- # Are users allowed to set their own From: address?
- # YES - Allow the user to specify their own From: address
- # NO - Use the system generated From: address
- #FromLineOverride=YES
- AuthUser=MAIL GMAIL
- AuthPass=PASSWORD
- useSTARTTLS=YES
- TLS_CA_File=/etc/ssl/certs/ca-certificates.crt
5. Test send mail.
- /usr/bin/php /var/www/check-sonoff.php
6. Create file for check ping to other server.
- nano check-sonoff.sh
insert code.
- #!/bin/bash
- SERVERIP=192.168.0.210
- ping -c 3 $SERVERIP > /dev/null 2>&1
- if [ $? -ne 0 ]
- then
- # Call php file send mail here:
- /usr/bin/php /var/www/check-sonoff.php
- fi
7. Test sell.
- bash check-sonoff.sh
8. Set crontab. run bash file.
- #Check Ping Sonoff Every 1 Hours
- 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
ไม่มีความคิดเห็น:
แสดงความคิดเห็น