I'm having an assignment where the lecturer is asking me to create a bash script to shut down a server at 11pm and turn it on at 6am. I'm able to do it by using sudo shutdown -h 23:00 and it works. But the problem is that I have no idea how to turn it on automatically on 6am, I couldn't find any commands that could do that. Any help would be appreciated.

  • Are you sure your assignment asks you to turn off the whole machine (and back on again), or just one server process? Obivously, the physical machine needs to be switched on to do anything.
    – Jos
    Mar 24, 2014 at 15:32
  • To be honest, I have no idea too, I also thought this would be impossible. The lecturer is being very vague on the assignment brief and its driving me nuts as well.
    – JLWK
    Mar 24, 2014 at 16:57

1 Answer 1


First you need to check if you can use the RTC wakealarm to wake your system:

sudo sh -c "echo 0 > /sys/class/rtc/rtc0/wakealarm"
sudo sh -c "echo `date '+%s' -d '+ 3 minutes'` > /sys/class/rtc/rtc0/wakealarm"
cat /sys/class/rtc/rtc0/wakealarm

Now check:

cat /proc/driver/rtc

This should return a list of parameters. Check the alrm_time is 3 minutes into the future and the alrm_date is today.

If it works ok, create a /usr/local/sbin/shutwake script:

sh -c "echo 0 > /sys/class/rtc/rtc0/wakealarm" 
sh -c "echo `date '+%s' -d '+ 7 hours'` > /sys/class/rtc/rtc0/wakealarm" 
shutdown -h now

Finally edit your user crontab, type crontab -e and add the following line:

0 23 * * * /usr/local/sbin/shutwake
  • I depends on BIOS clock settings, check /etc/default/rcS to see if UTC is set or not. Mar 24, 2014 at 16:59
  • Well, I tried exactly the same what you wrote above. It didn't worked:(. -Debian 8 Aug 1, 2016 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.