This is an old revision of the document!


#!/bin/bash ############################################################################################ #* Disk Monitoring Script by Michael Reber - v 1.0 # ############################################################################################

############################################################################################

## Variable Definition & System Vorbereitungen: diskToCheck='/dev/sda' today=`date +“%Y-%m-%d”`

# Before disk-check test, that disk is mounted! 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 "" \
	-o message-file="/tmp/smartInfo"
fi
exit 0

else

echo "Disk is not mountet!"

fi

  • skripting-section/bash/disk-monitoring-skript.1515090312.txt.gz
  • Last modified: 2018/01/04 19:39
  • (external edit)