Q:

Script to program periodic switch-on and off

My PC has a problem in its motherboard so when it's inactive for many hours after being on it won't start up, both when it's completely switched off or suspended. It takes between 8 to 18 hours to manage to start it up depending on how much work it had done previously.
So I figured it would be a solution never letting it be switched off or suspended, but completely active. The problem is this is a waste of energy. So I thought maybe it was possible to make a script that turns on and off the computer periodically. I guess it's impossible to turn it off completely because how is it going to execute the script if the computer is not switched on? So at least let it be suspended.
So what do you think? Is this achievable? I was thinking of using crontab and shutdown (or some similar command to suspend or hibernate) but I am not sure how to do this.
Any suggestion?

A:

rtcwake should be able to help you out here.
sudo rtcwake -m mem -s 15

That should enter a S3 (memory) suspend for a few seconds, all your fans will shut off... And then and then boot right back up again without any state loss. Even network connections remain intact here.
There is also a -m off mode. I'm going to assume you lose state completely here and AFAIK, only some BIOSes are equipped to power on from an off-state from RTC. Might be worth a shot if S3 doesn't work.

You can automate that with cron. Run sudo crontab -e and add something like:
0 */4 * * * rtcwake -m mem -s 15

That will run every four hours. It'll annoy the hell out of anybody using it when it goes to sleep, but that's apparently what you want.

But in all seriousness, this doesn't sound like a healthy underlying issue.
You might do well to fix or replace the broken parts, or at least diagnose it properly. You might be able to fix the problem completely or at least get it to the point that so when it does finally die, you know what needs replacing.
These things have a habit of kicking the bucket when you most need them.

