6

This script works perfectly when I launch it manually. How can I get it to run on startup? The function of the script is to get Docky to auto relaunch in the case of a crash.

I created the script like this:

  • gedit ~/process_monitor.sh

Pasted in the following (found it on Ask Ubuntu):

#!/bin/bash

if [[ -z "$1" ]];then
    echo "ERROR: must specify program"
    exit 1
fi

while (( 0 == 0 ));do
    $@ &
    pid=`jobs -l | awk '{print $2}'`
    wait $pid
done
  • Saved the file.

  • Set the permission:

    chmod a+x ~/process_monitor.sh
    

Now, when I run it like this, it works perfectly:

~/process_monitor.sh docky

However, when I add the following to startup applications, that does not make the script launch on startup. Well, maybe it does, but the script doesn't work.

/bin/bash ~/process_monitor.sh docky

enter image description here

Basically there's some sort of graphical element that flashes on the screen for half a second, but no other sign of the script to be seen, and Docky does not relaunch if it's killed.

How to make this work? I'm sure it's extremely basic.

I'm on Ubuntu 14.04.

Fiksdal
  • 2,121
  • Pipe your command to a tmp file when you add it to your startup, that will let you see if you the command is executing, and when it is, drop the error message. –  Mar 29 '16 at 12:46

2 Answers2

10

Using paths in a .desktop file

The issue is that Startup Applications creates a .desktop file in ~/.config/autostart

In a .desktop file, you cannot use relative- or variable paths like ~. Use absolute paths instead:

/bin/bash /absolute/path/to/process_monitor.sh docky
Jacob Vlijm
  • 83,767
0

This is better approach

run crontab -e insert this line at the bottom

*/2 * * * * if [ ! `pgrep docky` ] ; then /usr/bin/docky; fi

check if /usr/bin/docky command starts docky, that's it. This will check if docky is running every 2 minutes, if not it will start docky.

heemayl
  • 91,753
MRX
  • 371
  • 3
  • 4
  • 1
    This would make the assumption you're running a gui 100% of the time, or don't have a multi user system. While that's fine for most, I find it best to not set something that will be system wide regardless of the current state. –  Mar 29 '16 at 12:49
  • @MRX The other answer worked perfectly, so I don't see any reason to try this. – Fiksdal Mar 29 '16 at 13:47
  • 1
    Almost certainly, this will break from cron like this, since you need the DISPLAY -variable on GUI stuff. – Jacob Vlijm Mar 29 '16 at 14:42
  • 1
    Also, if Docky has crashed, I don't want to wait for up to 2 minutes for it to relaunch. It would then be quicker to launch it manually. – Fiksdal Mar 29 '16 at 14:53