OT: Casper DERRP

Not applicable

So I've been using this script to shut down any machines that were still logged in and in use after the MCX-supplied pmset shutdown time, and I was bonking my head for a few days why my logs were filling up with machines that then weren't shutting down:

#!/bin/sh

# check if a user is logged in, shutdown if current user is blank, do nothing otherwise

currentuser=`ls -l /dev/console | awk '{ print $3 }'`
        if [ "$currentuser" = "" ]; then
        echo "Shutting down..."
        /sbin/shutdown -h now
        exit 0
fi

exit 1

...Yeah, that last line "exit 1" was the problem. (Change that to "exit 0" if you use this.)

Curious if anyone else has any good recent DERRP moments. I CAN HAZ COMPUTE!

Always test before you deploy,

-p

1 REPLY 1

rockpapergoat
Contributor III

you could also include an else in there. i'd probably not specifically `exit 1` as a matter of course.