dbusを受け取り、メッセージのスクリプトをトリガーするデーモンを作成する方法

dbusを受け取り、メッセージのスクリプトをトリガーするデーモンを作成する方法

Ubuntuで画面のロックを解除するたびに、バックグラウンドでシェルスクリプトを起動するデーモンを作成したいと思います。関連する質問に対する回答に基づいて、次のスクリプトを作成できました。画面上でスクリプトを実行してロックとロック解除。端末ウィンドウではうまく動作します。しかし、今はそれからデーモンを作りたいのですが、まだ幸運ではありません。
どんな提案がありますか?

ベストアンサー1

に基づいて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

ただ接続してみてください/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 .

おすすめ記事