I just created a script (logscreenlock) to log lock/unlock screen events (derived from this post):
#! /bin/bash
dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" | ( while true; do read X; if echo $X | grep "boolean true" &> /dev/null; then echo `date` "screen locked"; elif echo $X | grep "boolean false" &> /dev/null; then echo `date` "screen unlocked"; fi done )
I wanted to have a startup daemon running logscreenlock > /var/log/screenlock.log
. Now, to write into /var/log, I need root permissions (I am a sudoer). So I would need sudo logscreenlock > /var/log/screenlock.log
, but I have two problems with that:
- logscreenlock is owned by my user and and I would like to keep it that way, but even after
chmod a+x logscreenlock
, I get permission denied if I try tosudo ./logscreenlock
. I tried tousermod -a -G <myusergroup> root
, but no luck. How can I overcome this? - How can I sudo in the startup applications? will it prompt me for a password right away?
EDIT: I found out later that the reason why I couldn't execute logscreenlock as root was that this script is in a remote filesystem where my machine's root is not authenticated.