I previously wrote about my adventures in setting up a Mac Mini to be a Home Theater PC (HTPC). Part of the Mini's duties, as a HTPC, are to periodically wake up and check various RSS feeds for updates. Unfortunately some of the feeds have a large number of updates daily and checking them once per day means missing updates that have scrolled out of their RSS feed. To insure I did not miss an update I began thinking about how to check each RSS feed multiple times a day while still allowing the Mini to sleep (for the most part) while not actively in use.
The first solution is obvious: Configure the Mini to wake up several times a day, check the feeds, and go back to sleep when done. Apple systems do support scheduled wake times (and scheduled power off times, though that's not what I'm looking for), but they're limited to a single event. You can instruct an Apple computer to "wake up at 08:00" but you can't instruct it to "wake up at 00:00, 08:00, and 16:00."
The second solution: Write a script that will run on my server that will pull the RSS feeds and combine them into a single feed with, say, 48 hours worth of cached updates in it. This would involve actually writing a script, and testing it, and it seemed suspiciously like work. Likewise for trying to find a web site that already offers such a aggregation → republish service.
That led me back to the first option. Some research told me that I could use a command line utility called pmset would allow me to set the power management preferences as well as the wake/poweron schedule. Combining this with cron would allow me to, in essence, accomplish my first (and preferred) solution.
The script used (inspired by this page):
#!/bin/bash
# pmset script
function usage
{
echo "Usage: [-h | --help] | [ [--midnight] [--morning] [--afternoon] ]"
}
if [ $(id -u) = "0" ]; then
echo
else
usage
echo "Must be run as root..."
exit 1
fi
# Reset our go-to-sleep pmset prefs just for fun.
# This can lead to a lot of confusion if someone tries
# to change things through the prefs panel.
#
# womp 1 == wake on magic packet
# displaysleep 0 == Don't waste effort trying to dim the display
# sleep 30 == sleep the system after 30 minutes of idle
# disksleep 3 == spin down HD after idle period
# autorestart 1 == restart after AC outage
pmset -a womp 1 disksleep 3 displaysleep 0 autorestart 1 sleep 30 2> /dev/null
mode=
case $1 in
--midnight ) mode=1
;;
--morning ) mode=2
;;
--afternoon ) mode=3
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
if [ "$mode" = "1" ]; then
pmset repeat wakeorpoweron MTWRFSU 08:00:00
fi
if [ "$mode" = "2" ]; then
pmset repeat wakeorpoweron MTWRFSU 16:00:00
fi
if [ "$mode" = "3" ]; then
pmset repeat wakeorpoweron MTWRFSU 00:00:00
fi
exitI combined this with a crontab (for user root) that runs the script with appropriate arguments one minute after the Mini wakes up:
1 0 * * * /Users/example/apps/wakeup_scheduler.sh --midnight >/dev/null 2>&1
1 8 * * * /Users/example/apps/wakeup_scheduler.sh --morning >/dev/null 2>&1
1 16 * * * /Users/example/apps/wakeup_scheduler.sh --afternoon >/dev/null 2>&1The script sets the wakeup schedule to the next wakeup time. For me this means the Mini will wake up three times a day at eight-hour intervals (00:00, 08:00. 16:00). You can adjust as needed.
Voila. The Mini now wakes up, does its RSS thing, and goes back to sleep. All is well in the world.
Next up - I think a Whamberry will make my remote-control of the Mini-when-it's-a-computer a more satisfying experience (my Harmony remote handles Plex just fine but is of course useless for things outside of Plex). I suspect that once I have it I will hate it with a passion, but for now I am breathlessly waiting for delivery. Far-down-the-road ... replace the HDD in the Mini with a SDD drive or Flash thumb drive that will be limited to holding the OS and, maybe, user files while shuffling the main file storage to an external HDD OR to NAS. This SHOULD allow the HDD to be in a lower-power spun-down state more often, and should keep "active" things on a disk with no moving parts. That should save a couple of watts, right?
Post new comment