CraftComputing / ProjectAxeEffect

40 stars 2 forks source link

Working bash/bc/snmpwalk example for MacOS and Linux #21

Open bignay2000 opened 3 months ago

bignay2000 commented 3 months ago

Script to run on MacOS & Linux and return error if temperature is greater than 75.00 degrees Fahrenheit. Uses BC to work around BASH's issues with decimals...

Works in Linux if the snmpwalk package is installed:

#!/bin/bash
set -E +u -o pipefail -e

ipaddress="192.168.50.93"

echo "Connecting to AxeEffect Temperature Sensor"
number=$(snmpwalk -v1 -c public $ipaddress iso.3.6.1.2.1.99.1.1.1.4.0 | awk '{ print $4 }')
C="${number:0:2}"."${number:2:2}"
echo "$C degrees Celcius"

F=$(echo "scale=2;((9/5) * $C) + 32" |bc)
echo "$(printf "%.2f" $F) degrees Fahrenheit"

if (( $(echo "$F > 75.00" |bc -l) ));
then
  echo "ERROR: Temperature greater than 75 degrees Fahrenheit."
  exit 1
else
  echo "Temperature less than 75 degrees Fahrenheit"
fi
bignay2000 commented 3 months ago

Be great to add this or something similar to the README in the repo. My use case is that I want a script that can be easily added to an existing Jenkins server to run a shell script and send an email alert on temperature with minimal dependancies or reliance on some unique monitoring solution.