Linux/Unix shell ??????????????
???????????? ???????[ 2013/5/9 11:33:20 ] ????????
????Linux??????????п???shell??????????????????DBA?????????????????????????????????????shell????????????????ο???
????1???????????п??shell???
robin@SZDB:~/dba_scripts/custom/bin> more ck_fs_space.sh
#!/bin/bash
# ------------------------------------------------------------------------------+
# CHECK FILE SYSYTEM 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 <percent> </filesystem [/filesystem2]> |
# |
# Author : Robinson |
# Blog :http://blog.csdn.net/robinson_0612 |
# ------------------------------------------------------------------------------+
#
# -------------------------------
# Set environment here
# ------------------------------
if [ -f ~/.bash_profile ]; then
. ~/.bash_profile
fi
export host=`hostname`
export mail_dir=/users/robin/dba_scripts/sendEmail-v1.56
exportmail_list='Robinson.cheng@12306.com'
exportmail_fm='oracle@szdb.com'
tmpfile=/tmp/ck_fs_space.txt
alert=n
# --------------------------------
# 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 above the threshold then send mail with df output
# ------------------------------------------------------------------------
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????????
????a???y??????? sendEmail ???????????????
????b????÷???"Usage:ck_fs_space.sh 90 / /u01" ??
????c???????????????while?????????ж????е????????????п????????????
????d?????????????????η?????????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11