2

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:

  1. 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 to sudo ./logscreenlock. I tried to usermod -a -G <myusergroup> root, but no luck. How can I overcome this?
  2. 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.

2 Answers 2

1

Assuming your username and group are ricab, have you tried sudo chgrp ricab /var/log/screenlock.log and sudo chmod g+rw /var/log/screenlock.log? You should then be able to read and write screenlock.log using your account.

2
  • That would work, but that's more of a workaround. I was looking for more general answers to the questions. "how can a user grant execute permissions to the root?" and "how can I run startup applications as root?". I will update my question to clarify that.
    – ricab
    Sep 11, 2013 at 13:52
  • Well, forget the previous comment, I just found out that the reason why I couldn't execute the script as root is because the script is in a remote filesystem (where my machine's root is not authenticated)... otherwise sudo would work just fine. So I will take your workaround after all, thanks!
    – ricab
    Sep 11, 2013 at 13:55
0

It's normal that you can't write to /var/log as a non-root user. Calling sudo is not a good solution. Don't elevate permissions unless they're actually needed for something. Write the log file in your home directory.

logscreenlock >~/.screenlock.log

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .