I'm trying to execute a bash command on screen lock/unlock.
Following tutorials & StackExchange questions, I came up with the following code:
#!/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 I launch the program with the following command:
nohup myprogram.sh & Everything works well at start, but after a while (several hours), there is no more echoed output when screen is locked/unlocked.
Checking the output of ps aux | grep mycommand, I have the following result at start:
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 After it breaks and does not emit messages anymore, then the ps output only shows one line.
I'm using CentOS 6.5, with Gnome 2.28 (and I unfortunately cannot upgrade to any newer version).
Would you have any insight about what could be happening and/or how to investigate further?
Edit: corrected the while true; then syntax error
while true; doetc.*) echo "`date` Unknown";;to the case statement, and run the command asnohup myprogram.sh </dev/null > $HOME/myprogram.out 2>&1 &.