3

i wrote a small script on python that calls a command line from the console in order to hibernate a linux machine (or shut itself down in case one word is changed) and then wake up after some time. The command is called again again and again through the watch command.

import os
import time

os.system("watch -n 20 sudo rtcwake -u -s 10 -m mem")

So the rtcwake command is called again 20 seconds after the pc has wokn up again. I would like another script to be run every time the computer wakes up. I already have this other script, it is a countdown. I want to do this in order to show the user how much time is left until the computer shut itself down again, but that second python script should also be called every time after the computer wakes up

Any ideas on this?? Thank you

user2013394
  • 149
  • 1
  • 1
  • 9

1 Answers1

2

If your kernel is configured to use APM, you should have a /etc/apm/resume.d directory where you could put some scripts executed whenever the system power state changes.

If you don't use APM (or if you don't want to be aware of this) try the /etc/pm/sleep.d or /usr/lib/pm-utils/sleep.d directories.

In every case, you could put in a script like this :

#!/bin/sh

case "$1" in
        resume)
                #Do what you need on resume
                ;;
        thaw)
                #Do what you need on thaw
                ;;
        suspend)
                #Do what you need on suspend
                ;;
        hibernate)
                #Do what you need on hibernate
                ;;
esac
Cédric Julien
  • 78,516
  • 15
  • 127
  • 132
  • In this case I would use the resume.d file. So I guess on that file i would invoke a command that runs that python counter right? – user2013394 Jul 25 '13 at 08:48
  • @user2013394 : yes, that's right but you don't always have a resume.d direcotry, sometimes it is sleep.d ;) – Cédric Julien Jul 25 '13 at 08:51
  • I have both :D in the sleep.d there are three different files and in the resume.d there is one single file. Both have the structure written by you in your answer. – user2013394 Jul 25 '13 at 08:54