Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- echo "---------------------------------------------"
- PIDFILE=/var/run/zfs/zfs_check.pid
- EXPECTET_RESULT="all pools are healthy"
- BAD_OUTPUT_FILE=/tmp/zfs_broken.log
- MAILADDR="someuser@example.com;otheruser@example.org"
- IFS=";"
- ZPOOL=/sbin/zpool
- send_mail() {
- echo "Sending mail to " $1
- echo $($ZPOOL status) | /usr/bin/mail -s $2 $1
- }
- if [ -e $PIDFILE ]
- then
- PIDC=$(/bin/cat $PIDFILE)
- echo "ZFS check is already running! PID: "$PIDC
- echo "Please use \"kill $PIDC\" to stop the Process (if you want to (because it hung,ect...))"
- echo "And remove the PID File by hand ($PIDFILE)"
- echo
- else
- echo "Creating PID file"
- PID=$(echo $$)
- echo $PID > $PIDFILE
- RESULT=$($ZPOOL status -x)
- if [ "$RESULT" = "$EXPECTET_RESULT" ]
- then
- #echo "Everything OK"
- echo $RESULT
- if [ -e $BAD_OUTPUT_FILE ]
- then
- echo "Normal working conditions reached."
- echo "Removing bad output file..."
- rm $BAD_OUTPUT_FILE
- set -- $MAILADDR
- for addr in $@
- do
- send_mail $addr "ZFS normal working conditions restored on $(hostname)"
- done
- fi
- else
- if [ -e $BAD_OUTPUT_FILE ]
- then
- echo "Already send something..."
- echo "Updating output log"
- date > $BAD_OUTPUT_FILE
- $ZPOOL status >> $BAD_OUTPUT_FILE
- else
- echo "SOMETHING IS WRONG!"
- date > $BAD_OUTPUT_FILE
- $ZPOOL status >> $BAD_OUTPUT_FILE
- set -- $MAILADDR
- for addr in $@
- do
- send_mail $addr "ZFS ERROR on $(hostname)"
- done
- fi
- fi
- echo "Removing PID file"
- /bin/rm $PIDFILE
- fi
- #---additional steps:
- #Create a folder (or change the above path in /var/run/)
- #mkdir /var/run/zfs/
- #
- #chmod +x /PATH/TO/THIS/SCRIPT.sh
- #
- #crontab -e
- ##ZFS Disk failure check
- #* * * * * /PATH/TO/THIS/SCRIPT.sh > /dev/null 2>&1
- #
- #---be sure that the user who executes the script can access the folder /var/run for PID file creation
- #---or just comment it out, if you don't want to crate a PID file
- #---zpool should obviously also be accessible for this user :)
- #
- #last update 2013-08-16
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement