Disk space check script for Linux
This is a simple script for Disk check, It will notify you via mail if your the disk space exceeded.Disk space check script for linux
Step1. Create a file
vim /root/diskcheck.sh
Copy/Paste the below script, then save the file
#!/bin/bash temp=`df -h |grep '/dev/vda2' | head -1 |awk '{print $5}' | sed 's/\%//g'`; if (($temp > 90)); then printf "Warning: Disk space running out. Check your mail for more information.\n"; printf "Warning: Disk Usage Above 90%%\n\ Current disk usage: $temp%%\n\ Remove unecessary files soon\n\ Take action soon\n" | mail -s "Disk space critical in `hostname`" [email protected]; fi
Step2. Set the permission
chmod 755 /root/diskcheck.sh
Step3. bash /root/diskcheck.sh
If you want to set it as cronjob
crontab -e 0 * * * * /root/diskspace.sh >/var/log/diskcheck.log 2>&1
save
That’s all