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?
1 Answer
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
-
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
.– muruAug 5, 2014 at 3:43
upstart
.