Maybe you run a physical Linux server somewhere under a desk or somewhere in your small office / home office which still contains spinning platters ( hard disks ) or any other hardware that “may fail” at some point. How do you get noticed that your server is in pain ? Send an automatic email ? Good Idea!! Way to go!
Who is reading it and when ?
Independent of that i prefer my physical servers to be AUDIBLE, to be able to cry for help, using the almost forgotten “on board pc speaker” that most (but not all) computers still have. But for whatever reason the pc speaker is ofen no longer “active” by default under Linux. So we need to enable it and make sure, that its driver is loaded on every reboot automatically.
This manual shows a way on how i enabled it and how i use it to alert me “audibly” when something critical on the server happens.
apt install beep
modprobe pcspkr
beep
# always make a backup first. # make sure it does not end on .conf # cp -v /etc/modprobe.d/blacklist.conf{,.$(date +%F)} # comment out corresponding kernel module # from blacklist # sed -i 's/blacklist pcspkr/#blacklist pcspkr/' /etc/modprobe.d/blacklist.conf
beep
still works, without “modprobing” manually again.#!/bin/bash # CHANGE LOG: # # 2021-08-01 A.Werner ADD: wall + console output + new string # clean,checking # # 2021-09-05 A.Werner ADD: new OK string added # function dit { beep -f 2750 -l 75 -d 50 } function dah { beep -f 2750 -l 175 -d 50 } function spc { sleep .1 } function s { dit dit dit spc } function o { dah dah dah spc } function morse_sos { s o s sleep .5 } mdState=$( /usr/sbin/mdadm --detail /dev/md0 | grep "State :" | cut -d: -f2 | tr -d ' ' ) case "$mdState" in active|active,checking|clean|clean,checking) : # nop ;; *) morse_sos echo "$0 WARNING: mdadm reports md0 status: '$mdState' on $(date)" >&2 echo "$0 WARNING: mdadm reports md0 status: '$mdState' on $(date)" >/dev/console wall "$0 WARNING: mdadm reports md0 status: '$mdState' on $(date)" ;; esac
chmod +x /usr/local/sbin/check-raid-status.sh
cat <<'EOF' > /etc/cron.d/raid-monitor-md0 # # Regular cron jobs to audibly alert admin if # md (mdadm) raid changes state from "clean" # using morse code # # #m h dom mon dow user command * 06-22 * * * root /usr/local/sbin/check-raid-status.sh EOF