【发布时间】:2019-09-08 13:43:04
【问题描述】:
我正在尝试在屏幕锁定/解锁时执行 bash 命令。
按照教程和 StackExchange 问题,我想出了以下代码:
#!/bin/bash
while true; do #added to try to solve the issue, but alas it did not
dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" |
while read sign; do
case "$sign" in
*"boolean false"*) echo "Screen unlocked";;
*"boolean true"*) echo "Screen locked";;
esac
done
done
我使用以下命令启动程序:
nohup myprogram.sh &
一开始一切正常,但过了一段时间(几个小时),屏幕锁定/解锁时不再有回显输出。
检查ps aux | grep mycommand的输出,我有以下结果开始时:
user <pid1> 0.0 0.0 <number> <number> pts/2 S 13:01 0.00 /bin/bash myprogram.sh
user <pid2> 0.0 0.0 <number> <number> pts/2 S 13:01 0.00 /bin/bash myprogram.sh
在它中断并且不再发出消息之后,然后ps 输出只显示一行。
我正在使用 CentOS 6.5 和 Gnome 2.28(很遗憾,我无法升级到任何更新的版本)。
您对可能发生的事情和/或如何进一步调查有任何见解吗?
编辑:更正了while true; then 语法错误
【问题讨论】:
-
没有运行你的代码——但我个人会在循环中引入一个小睡眠。
-
顺便说一句,外循环也应该是
while true; do等 -
在case语句中添加一行
*) echo "`date` Unknown";;,以nohup myprogram.sh </dev/null > $HOME/myprogram.out 2>&1 &运行命令。