Linux – Determine time of last suspend(-to-ram)

linuxsuspend

I have a backup script that is run each night. If my (Linux-) host is suspended it is woken up by another host before the script runs.

I would like to be able to suspend my host again after the backup is finished, but only if it was woken up to run the script. If it was running before, I want to leave it running.

Is there any way I can get the information when the host was last woken from suspend-to-ram?

Best Answer

Your distribution has a power management framework (this is clear because it is already suspending itself) that runs some scripts when it is about to suspend/hibernate/shutdown as well as when it resumes/turns on. If you do a search for " power management", you should be able to find good documentation about it.

The task probably involves simply placing a script in an appropriate directory. That script can be as simple as date +%s > /var/last-wake-time. Then your existing script would simply look at that file.

In general, not every distribution comes with power management utilities, and there are several tools tools to look at. You can check out acpid, uPower, pm-utils, and laptop-mode tools.

Related Question