I wish to write a bash script that executes on start up Ubuntu 13.04 and starts motion
whenever the screen is locked. Being a novice at bash scripting, I wasn't able to understand the various help sources available on the web and thereby write a script on my own. Anyways, I know that the following command is used to check if the system is locked:
gnome-screensaver-command -q | grep "is active"
But, if I use this command, I will have to periodically (say every 5-10 seconds) check the lock status. Is there a better alternative? Could someone provide me with a skeleton of the script?
So I could write the following script which starts the webcam once I lock the screen but does not stop it once sign back in. Any suggestions?
#!/bin/bash
while :
do
sleep 2
if (gnome-screensaver-command -q | grep "is active");
then
motion 2> ~/.motion/log
elif (gnome-screensaver-command -q | grep "is inactive");
then
/etc/init.d/motion stop 1> /dev/null
fi
done
sleep 5
to wait 5 seconds before you check again.