This script helps to notify me by e-mail about the condition of the disk. Remember to indicate the disk accordingly – in this case it is “/dev/sda” and change the e-mail address from “soban@soban.pl” to your own. Save the script in “/root/checkbadsector.sh“:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#!/bin/bash date > /root/badsectortest.txt badblocks /dev/sda -v &>> /root/badsectortest.txt hoursworkhdd=`smartctl --all /dev/sda | grep Power_On_Hours | awk '{print $10}'` dayworkhdd=`expr $hoursworkhdd / 24` yesworkhdd=`expr $dayworkhdd / 366` echo -e "Hours working hdd:" >> /root/badsectortest.txt echo -e $hoursworkhdd >> /root/badsectortest.txt echo -e "Days working hdd:" >> /root/badsectortest.txt echo -e $dayworkhdd >> /root/badsectortest.txt echo -e "Years working hdd:" >> /root/badsectortest.txt echo -e $yesworkhdd >> /root/badsectortest.txt date >> /root/badsectortest.txt cat /root/badsectortest.txt | /usr/bin/mail -s "badsector - `date`" soban@soban.pl |
You can also download it from https://soban.pl/bash/checkbadsector.sh:
1 2 |
# cd # wget https://soban.pl/bash/checkbadsector.sh |
Remember to grant permission to perform it:
1 |
# chmod +x /root/checkbadsector.sh |
On my server I added it once a month so that it would be performed periodically in the crontab:
1 2 |
# crontab -l | grep checkbadsector 30 17 20 * * /root/checkbadsector.sh > /dev/null 2>&1 |
You should receive an email similar to the one below:
Good luck and I wish you no errors!