This is an old revision of the document!
Disk Monitoring Skript
Skript, welches vom mir erstellt wurde, um automatisiert die Disk des backup-Servers auf SMART-Errors zu überprüfen.
Skript Sourcecode
Filename: disk_monitoring.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
#!/bin/bash ############################################################################################ #******************* Disk Monitoring Script by Michael Reber - v 1.0 **********************# ############################################################################################ ############################################################################################ ## Variable Definition & System Vorbereitungen: diskToCheck= '/dev/sda' today=` date + "%Y-%m-%d" ` # Optional: Before disk-check, test that disk is mounted! (Default Auskommentiert!) #if grep "$diskToCheck" /etc/mtab > /dev/null 2>&1; then ## System dependency Check: if [ -n "$(command -v apt-get)" ]; then if [ $(dpkg-query -W -f= '${Status}' smartmontools 2> /dev/null | grep -c "ok installed" ) - eq 0 ]; then apt-get update && apt-get install smartmontools sendemail libnet-ssleay-perl libio-socket-ssl-perl -y; fi else if [ $(yum -q list installed smartmontools &> /dev/null && echo "1" || echo "0" ) - eq 0 ]; then #yum install smartmontools -y; # TO DO exit 0 #systemctl start rpcbind && systemctl enable rpcbind; fi fi # Create Disk Smart-OUTPUT and check Status: OUTPUT= "$(smartctl -a /dev/sda > /tmp/smartInfo && grep -oP '(?<=test result: )[^ ]+' /tmp/smartInfo)" if [ "${OUTPUT}" = "PASSED" ] then echo "Disk is Healty!" exit 0 else echo "Disk detected a SMART-Error!" sendemail -f "mail.blackgate@gmail.com" \ -u "DETECTED A SMART-ERROR on `hostname`!" \ -t "michael.r467@gmail.com" \ -s "smtp.gmail.com:587" \ -o tls= yes \ -xu "mail.blackgate@gmail.com" \ -xp "PASSWORT" \ -o message- file = "/tmp/smartInfo" fi exit 0 #else # echo "Disk is not mountet!" #fi |