skripting-section:bash:disk-monitoring-skript

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
skripting-section:bash:disk-monitoring-skript [2018/01/05 12:33] – [Disk Monitoring Skript] michaelskripting-section:bash:disk-monitoring-skript [2018/09/25 13:52] (current) – [Skript Sourcecode] michael
Line 9: Line 9:
 #!/bin/bash #!/bin/bash
 ############################################################################################ ############################################################################################
-#******************* Disk Monitoring Script by Michael Reber - v 1.**********************#+#******************* Disk Monitoring Script by Michael Reber - v 1.**********************#
 ############################################################################################ ############################################################################################
- +
 ############################################################################################ ############################################################################################
  
Line 18: Line 18:
 today=`date +"%Y-%m-%d"` today=`date +"%Y-%m-%d"`
  
-Optional: Before disk-check, test that disk is mounted! (Default Auskommentiert!)+# Before disk-check test, that disk is mounted!
 #if grep "$diskToCheck" /etc/mtab > /dev/null 2>&1; then #if grep "$diskToCheck" /etc/mtab > /dev/null 2>&1; then
  
- ## System dependency Check: +uhubctl -a on -p 3 
- if [ -n "$(command -v apt-get)" ]; then +sleep 10 
- if [ $(dpkg-query -W -f='${Status}' smartmontools 2>/dev/null | grep -c "ok installed") -eq 0 ]; then +        ## System dependency Check: 
-   apt-get update && apt-get install smartmontools sendemail libnet-ssleay-perl libio-socket-ssl-perl -y; +        if [ -n "$(command -v apt-get)" ]; then 
- fi +                if [ $(dpkg-query -W -f='${Status}' smartmontools 2>/dev/null | grep -c "ok installed") -eq 0 ]; then 
- else +                  apt-get update && apt-get install smartmontools sendemail libnet-ssleay-perl libio-socket-ssl-perl -y; 
- if [ $(yum -q list installed smartmontools &>/dev/null && echo "1" || echo "0") -eq 0 ]; then +                fi 
-   #yum install smartmontools -y; +        else 
-   # TO DO +                if [ $(yum -q list installed smartmontools &>/dev/null && echo "1" || echo "0") -eq 0 ]; then 
-   exit 0 +                  #yum install smartmontools -y; 
-   #systemctl start rpcbind && systemctl enable rpcbind; +                  # TO DO 
- fi +                  exit 0 
- fi +                  #systemctl start rpcbind && systemctl enable rpcbind; 
- +                fi 
- # Create Disk Smart-OUTPUT and check Status: +        fi
- OUTPUT="$(smartctl -a /dev/sda > /tmp/smartInfo && grep -oP '(?<=test result: )[^ ]+' /tmp/smartInfo)"+
  
- if [ "${OUTPUT}" = "PASSED"+        # Create Disk Smart-OUTPUT and check Status: 
- then +        OUTPUT="$(smartctl -d sat -a /dev/sda > /tmp/smartInfo && grep -oP '(?<=test result: )[^ ]+' /tmp/smartInfo)" 
-   echo "Disk is Healty!" +        echo "$OUTPUT at $today" >> /var/log/disk-monitoring.log 
-   exit 0 +        if [ "${OUTPUT}" = "PASSED"
- else +        then 
-   echo "Disk detected a SMART-Error!" +          echo "Disk is Healty!" 
-   sendemail -f "mail.blackgate@gmail.com"   \ +        else 
- -u "DETECTED A SMART-ERROR on `hostname`!"     \ +          echo "Disk detected a SMART-Error!" 
- -t "michael.r467@gmail.com"+          sendemail -f "mail.blackgate@gmail.com"   \ 
- -s "smtp.gmail.com:587" +                -u "DETECTED A SMART-ERROR on `hostname`!"     \ 
- -o tls=yes \ +                -t "michael.r467@gmail.com"
- -xu "mail.blackgate@gmail.com"+                -s "smtp.gmail.com:587" 
- -xp "PASSWORT" \ +                -o tls=yes \ 
- -o message-file="/tmp/smartInfo" +                -xu "mail.blackgate@gmail.com"
- fi +                -xp "PASSWORD" \ 
- exit 0+                -o message-file="/tmp/smartInfo" 
 +        fi 
 +        # Poweroff Disk and exit program: 
 +        uhubctl -a off -p 3 
 +        exit 0
 #else #else
-# echo "Disk is not mountet!"+      echo "Disk is not mountet!"
 #fi #fi
 </sxh> </sxh>
  • skripting-section/bash/disk-monitoring-skript.1515151982.txt.gz
  • Last modified: 2018/01/05 12:33
  • by michael