Email Alert shell script

Source: Internet
Author: User

Note: you must first install an email server such as Postfix or Sendmail.

1. Apache

#!/bin/bash#apache.shnc -w2 localhost 80   if[ $? -ne 0 ]thenecho "apache is down,please check" | mail [email protected] -s "apache is down"/usr/local/apache2/bin/apachectl restartfi

Note:
NC goes to a port.-W2 indicates entering 2 seconds. If the port is enabled for 2 seconds, it automatically exits. If the port is not enabled, it exits directly.
$? Is the result of the previous execution. 0 indicates that the execution is successful. If the port is enabled, non-0 indicates that the execution fails, and the port is disabled.
If email sending is disabled on port 80 and the service is restarted

2. Hard Disk Quota

#!/bin/bash#disk.shnum=`df |awk ‘NR==3{print int($4)}‘`if [ $num -ge 20]thenecho "disk space is ${num}%, now >20%" | mail [email protected] -s "disk space >22%"fi

Note:
Num = 'df | awk' Nr = 3 {print int ($4)} '': Convert the value of column 3rd in the 4th rows of the DF execution result to int and assign the value to num.

 

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.