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?
Add a comment |
2 Answers
Based on https://askubuntu.com/questions/150790/how-do-i-run-a-script-on-a-dbus-signal
#!/bin/bash interface=org.gnome.ScreenSaver member=ActiveChanged dbus-monitor --profile "interface='$interface',member='$member'" | while read -r line; do echo $line | grep ActiveChanged && your_script_goes_here done 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 . - 1What 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 startto Startup Applications worked as charm. Great response time, thanks!lompy– lompy2013-06-20 16:04:04 +00:00Commented Jun 20, 2013 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-startupNate from Kalamazoo– Nate from Kalamazoo2013-06-20 16:44:18 +00:00Commented Jun 20, 2013 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– Aquarius Power2014-08-02 04:24:12 +00:00Commented Aug 2, 2014 at 4:24
There's already such a daemon in the system - upstart, you only need to make a session job for it.
description "some job description" start on desktop-unlock script /path/to/your/executable end script - Can you please elaborate? How do you create a session job for it? what is upstart? systemctl does not know any information regarding upstart.servicebrett– brett2020-01-08 13:37:43 +00:00Commented Jan 8, 2020 at 13:37
- @brett Since it is now in maintenace mode, you might need to install it separately. It used to be Ubuntu's "event-based cron on steroids" so to say. Session jobs are single user-specific tasks. Like stuff you'd get with
crontab -e. You create a.conffile with content like in this answer and put it in one of places listed here: upstart.ubuntu.com/cookbook/#session-jobOleg V. Volkov– Oleg V. Volkov2020-02-11 16:55:57 +00:00Commented Feb 11, 2020 at 16:55