Shell Programming disk monitoring (evaluate the available space depletion time, mail to the administrator)

Source: Internet
Author: User
Shell Programming disk monitoring (evaluation of available space depletion time, mail notification to the administrator) sets the monitoring disk to devmd0; if the file system usage is greater than 90%, the three functions are called in sequence to estimate the time used up by the file system, and the results are sent to the administrator .! BinbashThisscri shell programming disk monitoring (evaluation of available space depletion time, mail to the administrator) sets the monitoring disk to/dev/md0; if the file system usage is greater than 90%, the three functions are called in sequence to estimate the time used up by the file system, and the results are sent to the administrator. #! /Bin/bash # This script is used to monitor disk. #6/20/11 # define the write speed of the function compute file system function disk_speed () {A = 'df-k | grep "$1" | awk '{print $3} ''sleep 30 B = 'df-k | grep" $1 "| awk' {print $3} 'd = 'expr $ B-$ a' SPEED = 'expr $ D/30' echo $ SPEED unset a B D SPEED} # define estimated disk space depletion time function avai_time () {FREE = 'df-k | grep "$1" | awk '{print $4} ''if TIME = 'expr $ FREE/$ 2' then if [$ TIME- ge 60] then A = 'expr $ TI ME/60' echo $ A "minutes" unset free time return 0 else echo "Unknow" unset free time return 0 fi else echo "Unknow" unset free time return 1 fi} # Definition function content () {TEMP_FILE =/root/disk_monitor.tmp echo "Warning disk:" $1> $ TEMP_FILE echo "Used space:" $2 >>$ TEMP_FILE echo "Available space: "$3 >>$ TEMP_FILE echo" Use %: "$4" % ">>$ TEMP_FILE echo" Write speed: "$5 >>$ TEMP_FILE echo" Estimated Time remaining: "$6 >>$ TEMP_FILE echo" Now time: "'date +" % Y-% m-% d % H: % M "'> $ TEMP_FILE unset TEMP_FILE return 0} # define the file system to be monitored MON_DISK =/dev/md0USED = 'df-h | grep" $ MON_DISK "| awk' {print $5} '| sed's/% // ''# determines whether the usage rate is greater than 90%, if yes, run the statement after then if [$ USED-ge 90] then USED_SPACE = 'df-h | grep "$ MON_DISK" | awk '{print $4} ''avai_space =' df-h | grep "$ MON_DISK" | awk '{print $3} ''W_SPEED = 'disk _ speed $ MON_DIS K'if [$ W_SPEED! = 0] then S_TIME = 'avai _ time $ MON_DISK $ w_speed' else S_TIME = "Unknow" fi content $ MON_DISK $ USED_SPACE $ AVAI_SPACE $ USED $ W_SPEED $ S_TIME mail-s "Disk "warning "root
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.