--- /dev/null
+#!/bin/bash
+################################################################################
+#
+# sensors.generic
+# Bash Daemon for System Monitoring
+# Generic sensors plugin for monitoring temperature through lm_sensors
+#
+#
+#
+#
+###############################################################################
+
+# TRAP UNKNOWN ERRORS
+###############################################################################
+trap failure SIGTERM SIGINT SIGFPE
+
+failure()
+{
+ error "Something has gone SERIOUSLY wrong! (Received signal $?)"
+ return 255
+}
+
+error()
+{
+ printf "\e[41m" 1>&2
+ printf "ERROR: $1" 1>&2
+ printf "\e[0m\n" 1>&2
+}
+
+# VARIABLES
+###############################################################################
+SCRIPT=$0
+HOSTNAME=$2
+DELAY=$3
+LABEL=$4
+PATH=$5
+OUTPATH=/home/bdsm/out.fifo
+
+# MAIN FUNCTIONS
+###############################################################################
+help()
+{
+ echo "Generic temperature monitoring through lm_sensors"
+ echo "USAGE: $0 [FUNCTION] [HOSTNAME] [DELAY]"
+ echo "FUNCTION -- start/stop/status/help"
+ echo "HOSTNAME -- the hostname to monitor"
+ echo "::DELAY -- seconds between measurements"
+ exit 0
+}
+
+start()
+{
+ running=`ssh $HOSTNAME "cat /home/bdsm/.sensors.pid | \
+ xargs ps -T | \
+ grep -v PID | \
+ wc -l"` 2>/dev/null
+
+ if [ $running -eq 0 ] || [ $running -gt 5 ]; then
+ # Check if sensors is installed
+ installed=`ssh -q $HOSTNAME "sensors > /dev/null 2>&1; echo $?"`
+ if [ ! $installed ]; then
+ echo "" > $OUTPATH
+ return 1
+ fi
+
+ ssh -q $HOSTNAME <<EOF
+ while [ 1 ]; do
+ ts=`date '+%s'`
+ sensors | \
+ sed 's/ */ /g' | \
+ sed 's/[(].*[)]//g' \
+ | awk -v ts=$ts -v host=$HOSTNAME 'BEGIN {
+ line=1
+ } {
+ if($0 == "") {
+ line=0
+ } else if(line == 1) {
+ device=$0
+ } else if(line == 2) {
+ adapter=$2 $3 $4
+ } else if(line > 2) {
+ FS=":"
+ printf ts "|" host "|" device " " adapter " " $0 "\n"
+ FS=" "
+ } line=line+1
+ }' | tr ':' '|'
+ sleep $DELAY
+ done &
+EOF
+ ssh -q $HOSTNAME "ps aux | \
+ grep bdsm | \
+ grep sensors | \
+ grep -v grep | \
+ awk '{print \$2}' \
+ > /home/bdsm/.sensors.pid &"
+ else
+ echo "Already Running"
+ fi
+}
+
+stop()
+{
+ ssh $HOSTNAME "kill `cat /home/bdsm/.sensors.pid`"
+ ssh $HOSTNAME "rm /home/bdsm/.sensors.pid"
+}
+
+status()
+{
+ running=`ssh $HOSTNAME "cat /home/bdsm/.sensors.pid | \
+ xargs ps -T | \
+ grep -v PID | \
+ wc -l"`
+
+ if [ $running -eq 0 ]; then
+ echo "OFF"
+ else
+ echo "ON"
+ fi
+}
+
+# UTILITY FUNCTIONS
+###############################################################################
+
+formatConfig()
+{
+ # Reformat config file to be more machine-readable
+ # Removes whitespace and adds semicolons after property values
+ cat /home/bdsm/bdsm.conf | tr '\n' ' ' | sed 's/}/}\
+ /g' | sed 's/^;*//g' | sed "s/[[:space:]]//g"| \
+ sed 's/;\([{}]\)/\1/g' | sed 's/\([{}]\);/\1/g' \
+ > /home/bdsm/.bdsm.conf.tmp
+}
+
+# SCRIPT START
+###############################################################################
+
+# Get a list of configured hosts
+hosts=$(cat /home/bdsm/.bdsm.conf.tmp | cut -d'{' -f1)
+
+if [ -z $1 ]; then
+ help
+elif [ $1 == "start" ]; then
+ formatConfig
+ start
+elif [ $1 == "stop" ]; then
+ formatConfig
+ stop
+elif [ $1 == "status" ]; then
+ formatConfig
+ status
+elif [ $1 == "help" ]; then
+ help
+fi