Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create a daemon, which would fire up a shell script in the background every time I unlock the screen on my ubuntu. I managed to create such script according to answer to related question: run-script-on-screen-lock-unlock. And it works well in terminal window. But now I want to create a daemon from that and I didn't get any luck yet.
Any suggestions?

share|improve this question
up vote 3 down vote accepted

Based on http://askubuntu.com/questions/150790/how-do-i-run-a-script-on-a-dbus-signal



dbus-monitor --profile "interface='$interface',member='$member'" |
while read -r line; do
    echo $line | grep ActiveChanged && your_script_goes_here

Just stick that in /etc/init.d/monitor-for-unlock, make it executable, and then make a soft link in rc2.d

chmod +x /etc/init.d/monitor-for-unlock
cd /etc/rc2.d
ln -s /etc/init.d/monitor-for-unlock .
share|improve this answer
What exactly we are making link for in /etc/rc2.d? Is it autoload directory? Didn't quite worked for my ubuntu. But when added /etc/init.d/monitor-for-unlock start to Startup Applications worked as charm. Great response time, thanks! – lompy Jun 20 '13 at 16:04
Here's a conversation about rc2.d (System V init process) versus Ubuntu's upstart system: superuser.com/questions/151330/ubuntu-control-the-init-startup – Nate from Kalamazoo Jun 20 '13 at 16:44
any idea how to make it work with Unity? this is failing: ssudo dbus-monitor --profile "interface='com.canonical.Unity',member='Locked'" where Locked is about "com.canonical.Unity.Session.Locked", even if I use sudo... – Aquarius Power Aug 2 '14 at 4:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.