Linux shell script detects hard disk space mail alerts

Source: Internet
Author: User

Using http://www.weiruoyu.cn/?p=368

Shell script monitors hard disk space remaining space email alerts

1. First look at the disk, and how to use the script

    1. [[email protected] ~]# df -h
    2. File System                 capacity    used   available   used%  mount point
    3. /dev/mapper /volgroup00-logvol00
    4.                        8.9g  2.6g  5.9g  31%  /
    5. /dev/sda1               99m   13m   82m  13% /boot
    6. tmpfs                  188M      0  188M   0% /DEV/SHM
    7. [[EMAIL PROTECTED] ~]# DF  -h |sed -n  ' 3p ' |awk  ' {print $4} ' |cut -f 1 -d  '% '
    8. 31

2. Script (more than 70% alarms)

    1. #!/bin/bash
    2. disk_sda1=df -h |sed -n ‘3p‘|awk ‘{print $4}‘|cut -f 1 -d ‘%‘
    3. If
    4. ((disk_sda1 > 70));
    5. Then
    6. echo date "192.168.56.128" 70% "|mail-s" Disk over 70% "[email protected],[email protected]
    7. Fi

Script Backup (full test shell script)

    1. #!/bin/bash
    2. disk_sda1=df -h |sed -n ‘3p‘|awk ‘{print $4}‘|cut -f 1 -d ‘%‘
    3. If
    4. ((disk_sda1 > 80));
    5. Then
    6. echo "This is error"
    7. echo date "192.168.56.128" 70% "|mail-s" Disk over 70% "[email protected],[email protected]
    8. Else
    9. echo "This is OK"
    10. Fi

3. Scheduled Tasks

    1. [Email protected] tmp]# CRONTAB-E

Add to

3-hour Check

    1. * */3 * * */var/tmp/check_disk.sh

Or a 10-minute check.

    1. */10 * * * */var/tmp/check_disk.sh

=============================

Linux shell script detects hard disk space mail alerts

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.