I want to run some servers and whatnot on my machine but I don't want it to interfere with what I'm doing... Gaming, research, writing a paper, etc. My thought was to have a script run when the system idles as in when the screen is locked or no users are logged in. The stuff I would be running during idle would be things like a plex server, bitcoin miner or bittorrent. I can start and stop all of these things with something like "service plexd start/stop". Any ideas on how I can initiate these commands when the system goes into and comes out of idle?
Asked
Active
Viewed 1,438 times
1
1 Answers
2
I've created a new script to run a command upon locking and unlocking the screen because the others on the web don't work on 14.04. I set it as a startup program and added it to my sudoers file so that it can manage services on its own.
#!/bin/bash
while sleep 30s ; do
state=$(gnome-screensaver-command --query | grep -o "\w*active\w*" >> /dev/null)
if [[ $state == active ]]
then
./start.sh
else
./stop.sh
fi
done

leszakk
- 562
- 2
- 4
- 20
-
3A couple of suggestions: if
while [ 0 -le 1 ]
is supposed to be an infinite loop, you can simply usewhile true
. Better yet, in this case,while sleep 30s
and skip the sleep before thedone
. – muru Aug 05 '14 at 03:43
upstart
. – LittleByBlue Aug 04 '14 at 09:20echo $X
does not return anything for me – leszakk Aug 04 '14 at 18:43gnome-screensaver-command --query | grep -oh "\w*active\w*"
– leszakk Aug 04 '14 at 19:20