Skip to content
Advertisement

How to set cronjob on wake up from sleep? [closed]

For example if you want a cron job to run after each reboot, you add sth like this to your cron file:

JavaScript

Is there something similar to that for waking up from a sleep state?

Advertisement

Answer

This is not something that can be managed by cron, but it can be managed by the Power Management Utilities (pm-utils). When reading man pm-action, you find:

/etc/pm/sleep.d, /usr/lib/pm-utils/sleep.d: Programs in these directories (called hooks) are combined and executed in C sort order before suspend and hibernate with as argument suspend or hibernate. Afterwards, they are called in reverse order with argument resume and thaw respectively. If both directories contain a similar named file, the one in /etc/pm/sleep.d will get preference. It is possible to disable a hook in the distribution directory by putting a non-executable file in /etc/pm/sleep.d, or by adding it to the HOOK_BLACKLIST configuration variable.

So all you need to do is create a script in /etc/pm/sleep.d that looks like this:

JavaScript

Obviously, you can alter this if you do not want to distinguish between suspend and hibernate, or resume and thaw into something like:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement