linux cron sleep,linux - How to set cronjob on wake up from sleep? - Stack Overflow

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:

#!/usr/bin/env bash

action="$1"

case "$action" in

suspend)

# List programs to run before, the system suspends

# to ram; some folks call this "sleep"

;;

resume)

# List of programs to when the systems "resumes"

# after being suspended

;;

hibernate)

# List of programs to run before the system hibernates

# to disk; includes power-off, looks like shutdown

;;

thaw)

# List of programs to run when the system wakes

# up from hibernation

;;

esac

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

#!/usr/bin/env bash

action="$1"

case "$action" in

suspend|hibernate) stuff ;;

resume|thaw) stuff ;;

esac

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值