Hi Sorin,
The following script should help:
Code:
#!/bin/bash
# directory to be monitored
dir=/tmp
# limit on the size (in KB) of the directory
limit=9000
# alert email
email=you@domain.com
# if directory exists, find out it's size
if [ -d $dir ]
then
size=$(du -sk $dir | cut -f1)
else
echo "$dir is invalid !!!" | mail -s "Invalid directory" $email
exit
fi
# if directory size is greater than limit, alert the user
if [ $size -gt $limit ]
then
echo "Size of $dir is ${size}KB !" | mail -s "Directory size exceeded" $email
fi
Please put correct values for dir, limit and email. You can put this script as a cron job. For instance, if the path to the script is /home/sorin/monitor-dir.sh and you want to run the script every 15 minutes, then the cron job will be as follows:
*/15 * * * * /home/sorin/monitor-dir.sh
BTW make sure you make the script executable with the following command:
chmod 755 /home/sorin/monitor-dir.sh
Regards,
Lijeesh