0
無法進行修改以適應我的環境,這是check_disc函數,但在我的環境中通過/ dev/mapper /所連接的光盤無法正常工作,所以我有 for exmaple/dev/mapper/debian-var而不是/ var。從bash腳本BASH腳本修改用於自由空間監視目的
功能:
function check_disks {
THOLD=$1;
DISK_ERROR="";
# df -kl is the most portable options for df
MOUNTS=`df -lk | grep -v devfs | grep -v none | grep -v Filesystem | awk '{print $6}'`;
for MOUNT in $MOUNTS; do
PERCENT=`df -kl $MOUNT | grep -v Filesystem | awk '{print $5}' | sed 's/\%//'`;
if [ $PERCENT -gt $THOLD ]; then
DISK_ERROR="$DISK_ERROR Volume '$MOUNT' is at $PERCENT% usage.\n";
fi
done
if [ -n "$DISK_ERROR" ]; then
echo -en "ERROR: The following volumes have exceeded the allowable threshold of $THOLD% usage.\n$DISK_ERROR";
return 1;
else
return 0;
fi
}
輸出的DF -kl CMD:
df -kl
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/debian-root
1919048 493616 1327948 28%/
tmpfs 18717148 12 18717136 1% /lib/init/rw
udev 10240 784 9456 8% /dev
tmpfs 18717148 0 18717148 0% /dev/shm
/dev/cciss/c0d0p1 241116 23679 204989 11% /boot
/dev/mapper/debian-home
3842104 2681264 965668 74% /home
/dev/mapper/debian-tmp
4805760 366228 4195412 9% /tmp
/dev/mapper/debian-usr
3842104 1816200 1830732 50% /usr
/dev/mapper/debian-var
377857560 183429768 175233732 52% /var
此行應該改變我猜:
MOUNTS=`df -lk | grep -v devfs | grep -v none | grep -v Filesystem | awk '{print $6}'`;
但不知道如何。任何人都可以幫我一把嗎? THX
肯定的是,主要的問題是回答了,這將是方便的,如果我可以explude/home目錄,因爲如果得到充分但那不是可能導致警報當涉及到服務器穩定性時,真的很重要。這只是順便說一句:} – user1821820
只需添加'| 'MOUNTS'命令結尾處的'grep -v/home',這將消除'/ home'。如果那是你的意思。 –