Results 1 to 5 of 5

Thread: Running a command on wake-up from suspend

  1. #1
    Join Date
    Jul 2006
    Location
    London, UK
    Beans
    97
    Distro
    Ubuntu 9.10 Karmic Koala

    Running a command on wake-up from suspend

    I am running MythTV and have found that mythtv-backend prevents the computer from suspending. So, I wrote a simple script:
    Code:
    #!/bin/sh
    gksudo stop mythtv-backend
    gksudo pm-suspend
    This works perfectly and the computer resumes correctly (most of the time). However, I now need to restart the MythTV backend, which I currently do manually, via a desktop launcher that runs:
    Code:
    gksudo restart mythtv-backend
    I would like to be able to have this command (and maybe others) run when the machine resumes from suspend. I have read elsewhere about /etc/pm/sleep.d but I'm not sure how to put a "root" command in there, such as restarting a service...

  2. #2
    Join Date
    Apr 2007
    Location
    /dev/random
    Beans
    3,052

    Re: Running a command on wake-up from suspend

    Well, scripts in /etc/pm/*.d/ should be run with root privileges, so just omit the gksudos.
    Code:
    #!/bin/sh
    
    # Arguments can be:
    #    "suspend suspend"
    #    "resume suspend"
    #    "thaw hibernate"
    
    case "$1" in
            "suspend"
                    stop mythtv-backend
                    ;;
            "resume"
                    start mythtv-backend
    esac
    And save it as /etc/pm/sleep.d/90_mythtv-backend-fix or something.
    Last edited by Zorael; December 4th, 2009 at 09:17 AM.
    ...

  3. #3
    Join Date
    Jul 2006
    Location
    London, UK
    Beans
    97
    Distro
    Ubuntu 9.10 Karmic Koala

    Smile Re: Running a command on wake-up from suspend

    Quote Originally Posted by Zorael View Post
    Well, scripts in /etc/pm/*.d/ should be run with root privileges, so just omit the gksudos.
    Thanks!

  4. #4
    Join Date
    Jul 2010
    Beans
    16
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Running a command on wake-up from suspend

    Thanks, I wanted to do something else on resume and wondered where the script should go..

  5. #5
    Join Date
    Jan 2007
    Beans
    128
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Running a command on wake-up from suspend

    Hey, I don't really understand this stuff, but I'd like to run a command every time the computer wakes from sleep or hibernate. Should I modify #2 in this thread and save it as "/etc/pm/sleep.d/90_psmouse" ?

    It would be great if I understood what was happening here too.
    Thanks for any answers to this question.

    Code:
    #!/bin/sh
    
    # Arguments can be:
    #    "suspend suspend"
    #    "resume suspend"
    #    "thaw hibernate"
    
    case "$1" in
            "suspend"
                    sudo modprobe -r psmouse; sleep 2; sudo modprobe psmouse
    
                    ;;
            "resume"
                    sudo modprobe -r psmouse; sleep 2; sudo modprobe psmouse
    
    esac
    theWrk@Lh-owon-sun:~$ ssh larry@192.168.1.36
    larry@192.168.1.36's password:
    Last login: Fri Jan 16 01:07:10 2009
    larry@zapcon:~$ music123 ~/Music/Abba/"Dancing Queen.mp3"

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •