Skip to content

Instantly share code, notes, and snippets.

@noskla
Created December 14, 2019 15:30
Show Gist options
  • Save noskla/cf129b39aabf8d5e5637960c8c2dc34c to your computer and use it in GitHub Desktop.
Save noskla/cf129b39aabf8d5e5637960c8c2dc34c to your computer and use it in GitHub Desktop.
Bash script for my OpenBSD server that shows the CPU temperature and alerts me when it's getting too hot for my likings.
#!/bin/sh
if [ "$USER" != "root" ]; then
echo "Not running as root. PC speaker disabled.";
fi
while :; do
TEMP=$(sysctl -a | grep "hw.sensors");
TEMPRAW=${TEMP%".00 degC"*};
TEMPRAW=${TEMPRAW##*"temp0="};
if [ $TEMPRAW -gt 60 ]; then
OVERHEATING=1;
else
OVERHEATING=0;
fi
if [ "$OVERHEATING" == 1 ]; then
TEMPRAW="\033[0;31m$TEMPRAW*C\033[0;0m";
else
TEMPRAW="\033[0;32m$TEMPRAW*C\033[0;0m";
fi
if [ "$USER" == "root" ]; then
if [ "$OVERHEATING" = 1 ]; then
echo A > /dev/speaker;
fi
fi
echo -en "\rCPU: $TEMPRAW";
sleep 4;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment