1

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?

leszakk
  • 562
  • 2
  • 4
  • 20

1 Answers1

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
  • 3
    A couple of suggestions: if while [ 0 -le 1 ] is supposed to be an infinite loop, you can simply use while true. Better yet, in this case, while sleep 30s and skip the sleep before the done. – muru Aug 05 '14 at 03:43