Shell script detects root partition hard disk space utilization

Source: Internet
Author: User

#!/bin/bash

ip=$ (ifconfig eth0 |grep "inet addr" | awk ' {print $} ' |cut-f1-d ":") a=$ (df-h |grep/dev/sda2 |awk ' {print $} ' |cut-f1 -B "%") #截取分区使用率
If [$a-ge] then echo "$IP the server root partition is about to have no space, please clean it up in time. "|mail-s" $IP root partition detection "[email protected]
Fi

Here I use 163 mailbox, related settings to see the link

76038868 turn from CSDN

The above is originally written, SH direct execution without error and when the usage is greater than 80 o'clock, will send the relevant warning to the mailbox, but when the crontab timed task is written as follows:

*/2 * * * */shell_script/disk_check.sh

e-mail messages received in Chinese and $ip are not properly displayed, both of the causes of the problem are environment variables, the CRONTAB runtime is not the user's environment,

For Chinese garbled problem:

Echo $LANG First look at the language environment such as: ZH_CN. GB2312

Add a line to the script: Export LANG=ZH_CN. GB2312


The problem cannot be displayed for $ip:

Add a row to the script: Source/etc/profile

Shell script detects root partition hard disk space utilization

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.