Shell script for monitoring disk usage (local + remote) _linux shell

Source: Internet
Author: User
Tags disk usage
Monitordisk.sh is as follows
Copy Code code as follows:

#!/bin/bash
#Updated: 2008-03-03 PM by:leif (liangliwen@163.com)
Email=/usr/local/bin/email
/bin/df-h >/tmp/df.txt

Use= ' Df-h | Grep-o [0-9]*% | Grep-o ' [0-9]\+ ']

For I in $USE
Todo
if (($i > 95))
Then
$EAMIL-S "WARNING low disk spaces for $i" liangliwen@163.com break
Fi
if (($i > 90))
Then
$EMAIL-S "low disk spaces for $i" liangliwen@163.com fi
Done

/bin/rm-f/tmp/df.txt

To achieve the purpose, any one partition using to 90% to send a message to the designated recipient, to 95% on the subject of the message Warning (warning), instructions to send mail program email, is from Http://www.cleancode.org/projects/email Download and install, more flexible.

Put this shell on crontab to implement a timed check of the disk

The following are supplementary content:

Shell script for monitoring remote host disk usage, filename: disklog.sh
Copy Code code as follows:

#!/bin/bash
# FileName: disklog.sh
# Purpose: Monitoring the disk usage of remote systems
Logfile= "Diskusage.log"
if [[N $]]
Then
Logfile=$1
If
if [!-e $logfile]
Then
printf "%-8s%-14s%-9s%-8s%-6s%-6s%-6s%s\n" "Date" "IP Address" "Device" "Capacity" "Used" "Free" "Percent" "Status" > $logfile
Fi

ip_list= "127.0.0.1 0.0.0.0"
# provide a list of remote host IP addresses
(
For IP in $IP _list
Todo
SSH slynux@ $ip ' df-h ' | grep ^/dev/>/TMP/$$.DF

while read line;
Todo
cur_date=$ (Date +%d)
printf "%-8s%-14s" $cur _date $ip
echo $line | awk ' {printf ("%-9s%-8s%-6s%-6s%-8s", $1,$2,$3,$4,$5);} '

pusg=$ (echo $line | egrep-o "[0-9]+%")
pusg=${pusg/\%/};
If [$PUSG-lt 80];
Then
Echo SAFT
Else
Echo ALERT
Fi
done</TMP/$$.DF
Done
) >> $logfile

We can use cron to schedule script execution at a fixed interval, such as adding such an entry in crontab to enable the script to run automatically 10 o'clock in the morning every day:


* * */home/sh/disklog.sh/home/log/diskusg.log

Execute the CRONTAB-E command, add the line above and save it.

can also be performed manually:

$./disklog.sh
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.