Given below are some of the files to check the diskspace issue:
df -h
df -HP
du -hc /home/* --max-depth=1
## this command will give the files which are occupying more than 300MB space
find / -type f -size +300000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
# to monitor the disk space and sending alert mails
vi diskspace.sh
# change the path for output files
path='/home/kiran.chinta'
# alert email with hostname alias
myhostname=`hostname`
ADMIN="kiran.chinta@gmail.com"
# set alert level 80% as default if no user input found
ALERT=${1:-80}
mydate=`date '+%d %b %H:%M'`
df -HP | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
echo $output
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge $ALERT ]; then
# the message that will be written to a file, mail, SMS, Pop-up and Twitter
# the word space is black listed by SMS gateway
mymessage="$(hostname) running out of disk $usep percent full of $partition as on $mydate"
#find / -type f -size +600000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }' >> $path/testdisk.txt
# write to a file and email
echo "$mymessage" > $path/testdisk.txt 2>> $path/testdisk_err.txt
echo "the following files are occupying more space" >> $path/testdisk.txt 2>> $path/testdisk_err.txt
find / -type f -size +600000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }' >> $path/testdisk.txt
echo "$mymessage" | mail -s "$myhostname disk full " $ADMIN
fi
done
### put the above one in cronjob this will check every hour and every day if the space is more than 85% full
# disk space
00 */12 * * * /bin/sh -xv /home/kiran.sh/diskspace.sh 85 1>/home/kiran.chinta/disk_alert_succ.txt 2>>/home/kiran.chinta/disk_alert_err.txt

No comments:
Post a Comment