"Mauiwagen. Das Server." – pub 4096R/712DAA69

Bad disk detached and I wonder why, why, why, why, why.

freebsd_logoIn the last few days (or weeks, I’m not sure how long), one of my hard drive from one or the mirror array has been detached without my knowledge in my home FreeBSD server, acting as my NAS Storage. Luckly it was just a sata connection issue, after a quick fix, re-attaching back the lost drive was a breeze without any issue.

Learning from that event, where I am not sure how long the disk been detached, I came out with my own simple health check script that checks what I want and email me the result. Of cause to check the disk mirror status, most critical hardware and some services as well.

As usual, I would love to share this with the world.healthchecking You can use it as a base for your health check script and modify how you want.

However, it required another script, which originally created by cytopia{at} It was an awesome script that can retrieve all of your disks information, including the temperature (using smartctl tool). I also done some minor fix and modification to the original script ( to support data gathering on SSD as well, hence the script new name with my alias in it.

Direct fetch for both script here and

Maybe you been wonder why I didn’t use the more elegant Nagios monitoring for this. Reason is, I wanted to save all the resources as much as possible on the server.

Peek-a-boo of the script.


# maui[at], azmawee[at] azmawee[at]
# Version 1.0 – 20 Sep 2016 – Script lived.
# Version 1.1 – 21 Sep 2016 – Added APC and dmesg to the report.

# Script requirement:
# 1. script, original source from by <>.
# 2. smartctl tools (from smartmontools).
# 3. Mutt email client (Optional if you enable email notification).

# Notes.
# Run with option “–debug” to ignore email notification and only display report on screen for debugging.
# example: ./ –debug

# Email notification, 1 to enable, 0 to disable.

# Working path, default is in current directory (pwd)

# Log file

# dmesg log file

# Location to mutt

# List of emails
# Multiple recipients example : email_list=”,,”

#echo option/flag
show=”echo -e”

$show “`date` – Script started.\n” > $log

# General info
$show “`hostname` `ifconfig ng0 | grep inet | awk ‘{ print $2 }’ | tail -1` `uname -r -i`\n” >> $log

# Check APC UPS
$show “apcaccess status | grep -i -e status -e lastxfer:\n`apcaccess status | grep -i -e status -e lastxfer`\n” >> $log

# Check gmirror status
$show “gmirror status:\n`gmirror status`\n” >> $log
$show “gmirror list | grep -i name:\n`gmirror list | grep -i name:`\n” >> $log

# Check current attached disk(s)
$show “Current attached disk(s):\n`$wpath/`\n” >> $log

# Check diskspace
$show “df -H:\n`df -H`\n” >> $log

# Check squid status
$show “service squid status:\n`sh /rc.d/squid status` Background pid check for squid is `ps auwx | grep “(squid)” | head -1 | awk ‘{print $2}’`.\n” >> $log

# Check samba status
$show “service samba_server status:\n`service samba_server status | grep nmbd` Background pid check for nmdb is `ps auwx | grep nmbd | head -1 | awk ‘{print $2}’`.” >> $log
$show “`service samba_server status | grep smbd` Background pid check for smbd is `ps auwx | grep smbd | head -1 | awk ‘{print $2}’`.\n” >> $log

# Check Apache(httpd) status
$show “service apache22 status:\n`service apache22 status` Background pid check for apache is `ps auwx | grep /usr/local/sbin/httpd | head -1 | awk ‘{print $2}’`.\n” >> $log

# Check MariaDB/Mysql server status
$show “service mysql-server status:\n`service mysql-server status` Background pid check for mysqld is `ps auwx | grep /usr/local/libexec/mysqld | head -1 | awk ‘{print $2}’`.\n” >> $log

# Check named status
$show “service named status:\n`service named status` Background pid check for named is `ps auwx | grep /usr/local/sbin/named | head -1 | awk ‘{print $2}’`.\n” >> $log

# grep 30 current dmesg
$show “dmesg | tail -30:\n`dmesg | tail -30`\n” >> $log

$show “`date` – Script ended.” >> $log

if [ “$1” == “–debug” ]; then
cat $log
# Email the report
if [ “$email_notification” == “1” ]; then
$_mail -s “ server check” — $email_list < $log

, , , , , , , , , , , , , ,

Leave a Reply

Be the First to Comment!

Notify of
MaUi^ - pub 4096R/712DAA69
Fingerprint 8BF7 D0AF CA45 5313 A3BF ACFB B90B 66C7 712D AA69