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. Fall die Disk die SAMRT-Prüfung nicht mehr besteht, so wird ein Email an den Administrator gesendet!
Skript Sourcecode
Filename: disk_monitoring.sh
#!/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