Hello.

I'm not a proficient shell script writer, so I would like advice
and criticism for my sensorsd(8) temperature script.

In particular, I would like the "above" email to root to include helpful
information that would help explain why the temperature went to critical.
Anything else that I may be missing would be nice to know too, including
scripting style.

 $ cat /etc/sensorsd/temp.sh
#!/bin/sh

case $1 in
"below")
        # Normal operation.
        apm -A
        ;;
"within")
        # We hit the warning threshold. Step down the CPU.
        apm -L
        # Write the warning to syslog, so we know why the CPU was stepped
down.
        logger -t "$0" "Reached warning temperature. Stepping down CPU."
        # Tell root.
        echo "Stepping down CPU due to high temperature" | mail -s "$0"
root@`hostname`
        # Tell users:
        echo "Stepping down CPU due to high temperature" | wall
        ;;
"above")
# Mail message for root, with hopefully helpful information.
message="
The system was shut down due to excessive temperature.
The system hardware may need maintenance.

System information:
`date`
`uptime`
`who -u`

`sysctl hw.sensors`
`sysctl hw.cpuspeed`
`sysctl hw.setperf`

`ps auxw`
"
        # Mail root.
        echo "$message" | mail -s "$0" root@`hostname`
        # Halt and power down.
        shutdown -h -p now "Reached critical temperature. Halting system
from $0"
        ;;
esac

Reply via email to