Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
    
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 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. –  Jeremy Lai Wai Kit Mar 24 at 16:57

1 Answer 1

up vote 5 down vote accepted

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:

#!/bin/bash 
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
share|improve this answer
    
I depends on BIOS clock settings, check /etc/default/rcS to see if UTC is set or not. –  Sylvain Pineau Mar 24 at 16:59
    
Alright thanks! It worked! –  Jeremy Lai Wai Kit Mar 24 at 17:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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