shut down linux server and turn on automatically at specific time
Solution 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:
#!/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