1

I have the habit of quickly setting some reminders with:

sleep $duration; notify-send $reminder_message

But lately I have had to move around and often change desks. I noticed that my $reminder_message started arriving later than intended. The culprit, it turn out is: that when I close lid then it suspends everything along with my sleep command.

Here's how I found out:

date; echo $duration; date -d "+$duration sec"; sleep "$duration"s; date

If I close my lid in between the above command then: date and date -d "+$duration sec" don't match. However if lid is not closed then they match!

So for a quick-fix I have disabled suspend with lid-close with:

HandleLidSwitch=ignore

(following this ask-ubuntu answer)

Now my sleep commands work as I wanted them to. But disabling suspend altogether I feel is a too aggressive fix and an overkill!

Is there a simpler solution? I just want that my sleep commands shouldn't be interrupted when I close my lid.

Inspired_Blue
  • 601
  • 2
  • 11
  • 26

1 Answers1

2

No offense, but we may have an XY problem here. Your impression that the solution to your real problem is with sleep may be wrong. sleepchecks until the specified time has passed, and that time stops when the computer sleeps.

Instead consider using the at command to schedule specific jobs to happen at a specific time.

at works like this:

echo "command_to_be_run" | at +30 minutes

will schedule a job 30 min later.

at is a lot like cron, but a job is run only once. It is not installed by default, but can be installed with sudo apt install at.

vanadium
  • 97,564