cancel
Showing results for 
Search instead for 
Did you mean: 

check system

Son dam bi
Advisor

check system

I would like to write a script to check do the system ,

if the directory size larger than xxx KB or no.of files is more that xxx , then send alert mail to me , can adivse what can i do ?

can advise what can i do ? thx
3 REPLIES
V. Nyga
Honored Contributor
Stephan.
Honored Contributor

Re: check system

Hi,
hopefully i did understand correct what you need - try this:

#!/usr/bin/sh
alert=0
alertsize=20000
alertfiles=500
alertemail=someone@domain.com
checkdir=/tmp

checksize=$(bdf $checkdir | tail -n 1 | awk '{print $3}')
checkcount=$(ll $checkdir | wc -l)

if [[ $checksize -ge $alertsize ]]
then
alert=1
fi

if [[ $alert = 1 ]]
then
echo "$(hostname): $checkdir contains $checkcount files and has $checksize kb used Space" | mailx -s "ALERT" $alertemail
fi
Stephan.
Honored Contributor

Re: check system

ops, just saw that i missed a part, please use this ...

#!/usr/bin/sh
alert=0
alertsize=20000
alertfiles=500
alertemail=someone@domain.com
checkdir=/tmp

checksize=$(bdf $checkdir | tail -n 1 | awk '{print $3}')
checkcount=$(ll $checkdir | wc -l)

if [[ $checksize -ge $alertsize ]]
then
alert=1
fi

if [[ $checkcount -ge $alertfiles ]]
then
alert=1
fi

if [[ $alert = 1 ]]
then
echo "$(hostname): $checkdir contains $checkcount files and has $checksize kb used Space" | mailx -s "ALERT" $alertemail
fi