我想创建一个守护进程,每次我在 ubuntu 上解锁屏幕时,它都会在后台启动一个 shell 脚本。我设法根据相关问题的答案创建了这样的脚本:run-script-on-screen-lock-unlock。它在终端窗口中运行良好。但是现在我想从中创建一个守护进程,但我还没有运气。
有什么建议?
基于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
Run Code Online (Sandbox Code Playgroud)
只需将其粘贴在/etc/init.d/monitor-for-unlock 中,使其可执行,然后在 rc2.d 中创建软链接
chmod +x /etc/init.d/monitor-for-unlock
cd /etc/rc2.d
ln -s /etc/init.d/monitor-for-unlock .
Run Code Online (Sandbox Code Playgroud)