Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there any way to prevent temporally suspend/hibernate from a script?

I want the screen to enter in powersave mode when appropriate, but the computer doesn't stop. Caffeine doesn't allow this: it disables all or nothing.

Why I want to do this? Because sometimes I download huge amount of files from a server via FTP. These downloads can take hours to complete.

share|improve this question

1 Answer 1

To prvent hibernation, create /var/run/do-not-hibernate:

sudo touch /var/run/do-not-hibernate

The file /usr/lib/pm-utils/sleep.d/000kernel-change makes this work. If you need to disable suspend, create a new file for that, say /etc/pm/sleep.d/000_prevent_suspend_hibernate:

# Prevents the machine from suspending or hibernating when
# the file /var/run/do-not-hibernate-or-suspend exist
case "$1" in
    [ -f /var/run/do-not-hibernate-or-suspend ] && exit 1

Make it executable:

sudo chmod +x /etc/pm/sleep.d/000_prevent_suspend_hibernate

In case you need to prevent the machine from suspending or hibernating, create a file:

sudo touch /var/run/do-not-hibernate-or-suspend

After rebooting or removing this file, suspending and hibernating works again.

share|improve this answer
Thanks. I'll test your script with a little change. Instead of create the file /var/run/do-not-hibernate-or-suspend, I'll test the existence of a lftp process active with "pidof lftp". –  Simón Oct 9 '11 at 16:00
It doesn't work. I think these scripts aren't used. Because the pm-suspend.log shows lines like: "/usr/lib/pm-utils/sleep.d/...". I'll test moving the script to this folder: /usr/lib/pm-utils/sleep.d/ –  Simón Oct 10 '11 at 8:52
I thought that exit 1 would stop the hibernate process but it doesn't. I'm testing now with: . "${PM_FUNCTIONS}" ... pidof lftp && inhibit –  Simón Oct 10 '11 at 12:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.