Linux/Unixshell script monitors available disk space

Source: Internet
Author: User
Linux/Unixshell scripts monitor disk space available Linux shell scripts that monitor disk free space, which are essential for system administrators or DBAs. The following is a sample shell script for monitoring disk space for your reference. 1. monitor the free space of the disk... linux/Unix shell scripts monitor disk space available Linux shell scripts that monitor disk free space, which are essential for system administrators or DBAs. The following is a sample shell script for monitoring disk space for your reference. 1. monitor the free space of the disk. shell script [python] robin @ SZDB :~ /Dba_scripts/custom/bin> more ck_fs_space.sh #! /Bin/bash # Scripts + # check file sysysytem space by threshold | # Filename: ck_fs_space.sh | # Desc: | # The script use to check file system space by threshold | # Once usage of the disk beyond the threshold, a mail alert will be sent. | # Deploy it by crontab. e.g. per 15 min | # Usage: | #. /ck_fs_space.sh | #|# Author: Robinson | # samples + ## ----------------------------- # Set environment here # ---------------------------- if [-f ~ /. Bash_profile]; then .~ /. Bash_profile fi export host = 'hostname' export mail_dir =/users/robin/dba_scripts/sendEmail-v1.56 export mail_list = 'Robinson. cheng@12306.com 'export mail_fm = 'Oracle @ szdb.com 'tmpfile =/tmp/ck_fs_space.txt alert = n # handle # Check the parameter # ------------------------------ max = $1 if [! $ {2}]; then echo "No filesystems specified. "echo" Usage: ck_fs_space.sh 90 // u01 "exit 1 fi # -------------------------------- # Start to check the disk space # while [" $ {2} "] do percent = 'df-P $ {2} | tail-1 | awk '{print $5}' | cut-d '%'-f1 'if ["$ {percent}"-ge "$ {max}"]; then alert = y break fi; shift done ;#--------------------------------------------- --------------------------- # When a partition was abve the threshold then send mail with df output # else if [! "$ {Alert}" = 'n']; then df-h> $ tmpfile mail_sub = "Disk usage beyond the threshold $ {max} on $ {host }. "$ mail_dir/sendEmail-u $ {mail_sub}-f $ mail_fm-t $ mail_list-o message-file =$ {tmpfile} fi; exit; 2. Script Description a. This script uses the sendEmail tool to send emails. B. The Usage is "Usage: ck_fs_space.sh 90 // u01 ". C. a while loop is used in the script to determine whether the free space of all specified partitions exceeds the threshold value one by one. D. send an email when the threshold value is exceeded and attach the disk space usage of the current server.
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.