How to monitor disk space in Linux boxes

Sometimes, you will need to monitor your disk space on some linux servers in your network. You may install monitoring tools like Zabbix, however this may be too much, may be you just need to monitor disk usage on the box. You can use this script to e-mail you every morning with the disk usage on the box:

#!/bin/sh
address="root@localhost";
cicl="2 3 4 5 6";
# ?????????? ? ????????? ????? ???????????? ????? ??? ??????? ???????,
# ??? ??????? ?????????? ?????????
predel[2]=80;	# /
predel[3]=80;	# /usr
predel[4]=60;	# /var
predel[5]=80;	# /tmp
predel[6]=80;	# /home
varning=”0″;

count=0;
df -h > /tmp/tmp_df;
while read -r FS S Ud A U MO; do
	let count+=1;
	FileSystem[$count]=$FS;
	Size[$count]=$S;
	Used[$count]=$Ud;
	Avail[$count]=$A;
	Use[$count]=$U;
	MountedOn[$count]=$MO;
	NUse[$count]=${Use[$count]%”%”};
done < /tmp/tmp_df;
table=”";
for c in $cicl; do
	if [[ ${NUse[$c]} -ge ${predel[c]} ]]; then
		varning=”1″;
		table=$table”n${FileSystem[$c]} t${Size[$c]} t${Used[$c]} t${Avail[$c]} t${Use[$c]} t${MountedOn[$c]}”;
	fi
done
		shapka=”nFileSystem tSize tUsed tAvail tUse tMounted On”;
		body=”Regard admin, please check, place on disk:”$shapka$table;
		#echo -e $body;
if [ $varning -eq "1" ];
    then
	echo -e $body | mail -s”Warning on server” $address;
	logger -i -p cron.warn -t dfmonitor “Send warning to $address”;
    else
	logger -i -p cron.info -t dfmonitor ” Place on disk in rate”;
fi

You can call this shell script whatever you want and don’t forget to add this into your crontabs.

The script is courtesy of OpenNet.Ru

Comments

One Response to “How to monitor disk space in Linux boxes”

  1. synack on May 11th, 2007 3:47 am

    I’ve got something similar… It’s not bullet-proof :)

    #!/bin/bash

    for X in `df -hl | grep -vi use | awk ‘{print $5}’ | sed -e ’s/\%//g’`; do
    if [ $X -gt 50 ]; then
    echo `df -hl | grep $X`;
    fi;
    done

Leave a Reply

You must be logged in to post a comment.

Categories


Clicky Web Analytics