LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-17-2013, 09:21 PM   #1
bubuntu
Member
 
Registered: Nov 2009
Location: Huntsville, Al
Distribution: Ubuntu
Posts: 34

Rep: Reputation: 2
Script to capture gnome-screensaver event doesn't work if run as root


I am trying to run scripts when gnome-screensaver starts or stops in Ubuntu. If I set up the scripts as described it works fine. I can't get it to work as root.

Here is the script ssTriger copied from the referenced web site with a small change (used "call" instead of "Popen" to invoke the scripts to run at start and stop of screen saver activation):

Code:
#!/usr/bin/env python
from gobject import MainLoop
from dbus import SessionBus
from dbus.mainloop.glib import DBusGMainLoop
from subprocess import Popen
from subprocess import call

class SSTrigger:
    def __init__(self):
        DBusGMainLoop(set_as_default=True)
        self.mem='ActiveChanged'
        self.dest='org.gnome.ScreenSaver'
        self.bus=SessionBus()
        self.loop=MainLoop()
        self.bus.add_signal_receiver(self.catch,self.mem,self.dest)
    def catch(self,ssOn):
        if ssOn == 1: #Screensaver turned on
#            call(["echo", "'opt/ssTrigger/ssStart'"])
            call(["sudo", "/opt/ssTrigger/ssStart"])
            #Popen(["/opt/ssTrigger/ssStart"])
#            call(["sudo", "ifconfig","eth0","down"]) #works if ifconfig set in sudoers
        else: #Screensaver turned off
#            Popen(["/opt/ssTrigger/ssStop"])
#            call(["echo", "'opt/ssTrigger/ssStop'"])
#            call(["sudo", "ifconfig", "eth0", "up"]) #works if ifconfig set in sudoers
            call(["sudo", "/opt/ssTrigger/ssStop"])

SSTrigger().loop.run()
ssStart is:
Code:
#!/bin/bash
echo "start"
#sudo ifconfig eth0 down
ifconfig eth0 down
exit
ssStop is:
Code:
#!/bin/bash
echo "stop"
#sudo ifconfig eth0 up
ifconfig eth0 up
exit
Both ssStart and ssStop are owned by root. These and ssTriger (owned by me) are in /opt/ssTrigger as per the referenced web page I got all this from.

Also have added this to /etc/sudoers so I don't have to enter my password when the scripts run.
Code:
user_me ALL=(ALL) NOPASSWD: /opt/ssTrigger/ssStart
user_me ALL=(ALL) NOPASSWD: /opt/ssTrigger/ssStop
I'm running ssTrigger from a terminal window and it works flawlessly but when I run it as root it won't capture the screen saver start or stop event. If I could do this then I could get rid of the scripts and "call(["sudo", "ifconfig", "eth0", "down"])" instead.

This is a potential solution to a question I posted a while back where I want to put internet connection to sleep if no user activity but haven't had time to try and solve till now.

Any help will appreciated.
 
Old 01-19-2013, 09:52 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
What error message do you get when run as root?
 
Old 01-21-2013, 10:51 AM   #3
bubuntu
Member
 
Registered: Nov 2009
Location: Huntsville, Al
Distribution: Ubuntu
Posts: 34

Original Poster
Rep: Reputation: 2
None. It just doesn't capture the screen saver start and stop events. Suddenly today it doesn't capture the events even if I run as me.
 
Old 01-22-2013, 04:48 AM   #4
bubuntu
Member
 
Registered: Nov 2009
Location: Huntsville, Al
Distribution: Ubuntu
Posts: 34

Original Poster
Rep: Reputation: 2
Just discovered that gnome-screensaver isn't running. Now I have to find out why. It has always started automatically as far as I know, but now it doesn't. Did an update just before I noticed the problem, maybe that had something to do with it. Will keep digging as time permits.

Last edited by bubuntu; 01-22-2013 at 04:48 AM. Reason: punctuation
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Root user check in bash script doesn't work tawalker Programming 6 12-18-2011 03:06 AM
Script run at startup doesn't work under Ubuntu 10.04 LTS DSchuler Linux - Newbie 6 05-03-2011 07:42 PM
screensaver doesn't work in Mint7 KlausG Linux - Newbie 6 06-04-2009 03:20 AM
Shell script to start MPlayer doesn't work in any other directory than /root lagu2653 Programming 5 04-28-2006 03:22 AM
KDE - screensaver doesn't work nigham Linux - Software 5 10-07-2003 09:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration