1

I am on Ubuntu GNOME 15.10 with GNOME 3.18, but I don't like the normal applications launcher so I have installed Docky, however often Docky suddenly closes and I am forced to manually restart it, so I was wondering how I could make a daemon which runs all the time in the background that would check at regular intervals if Docky is running, and if it is not, run it?

1 Answers1

1

Create a script anywhere you want it to be, preferably in your home directory. I like to call mine, check_docky.bsh. In your script, do the following lines:

#!/bin/bash

ps -ef | grep -i docky.exe | grep -v grep >/dev/null

case $? in
1) sh -c "mono /usr/lib/docky/Docky.exe";;
0) exit 0;;
esac

In the above script, the ps -ef | grep will look to see if Docky is running. If it is not running the exit code that gets returned is 1, so then the case statement would relaunch Docky automatically. Else, the script would exit normally with a code 0.

Make sure the script is executable:

chmod +x check_docky.bsh

Then create a cron job for the script.

First, run crontab as you:

$ crontab -e

Then as a new entry add the following so that it will check every 10 minutes starting at :00 of the hour:

# m h  dom mon dow   command
*/10 * * * * /home/<username>/check_docky.bsh

To show that this command works:

~$ ps -ef | grep wookie | grep -v grep
~$ echo $?
1
~$ ps -ef | grep wookie
terrance  20978  6976  0 13:53 pts/17   00:00:00 grep --color=auto wookie
~$ echo $?
0

Hope this helps!

Terrance
  • 41,612
  • 7
  • 124
  • 183
  • This answer is flawed as the exit code use will always be 0 due to grep -v grep always matching. You need to move that statement after ps -ef | grep -v grep or something like that. – 13m5 May 10 '18 at 18:57
  • @13m5 Check edit. Please test before you comment. – Terrance May 10 '18 at 19:55
  • @13m5 There is nothing wrong with that statement. I don't write answers that I don't test. grep -v grep makes it so that grep doesn't find itself as a process because technically it is a process at the moment. I know that there are other ways to do this, but this method works fine. – Terrance May 11 '18 at 14:25