Created
April 19, 2019 06:48
-
-
Save ilumos/a523fcafe2463cf1dca52e95afcbd685 to your computer and use it in GitHub Desktop.
Schedule a wake for up to 23 hours in the future, and then shut down
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
HOURS_FROM_NOW=${1,,} | |
if ! [[ $HOURS_FROM_NOW =~ ^-?[0-9]+$ ]] ; then | |
echo 'Argument "hours from now" must be an integer' | |
exit 1 | |
fi | |
if ! [[ $HOURS_FROM_NOW < 24 ]] ; then | |
echo 'Argument "hours from now" must be less than 24' | |
exit 1 | |
fi | |
echo "Clearing existing RTC wake alarms" | |
sh -c "echo 0 > /sys/class/rtc/rtc0/wakealarm" | |
echo "Setting wake alarm for $HOURS_FROM_NOW hours from now" | |
#sh -c "echo `date '+%s' -d '+ "$HOURS_FROM_NOW" hours'` > /sys/class/rtc/rtc0/wakealarm" | |
NOW=$(date +%s) | |
WAKE_TIMESTAMP=$((NOW+(HOURS_FROM_NOW*3600))) | |
sh -c "echo ${WAKE_TIMESTAMP} > /sys/class/rtc/rtc0/wakealarm" | |
echo "Shutting down now" | |
/sbin/shutdown -h now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment