Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ~/

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


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

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

  • Set the permission:

    chmod a+x ~/

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

~/ 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 ~/ 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.

share|improve this question
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. – bc2946088 Mar 29 at 12:46
up vote 9 down vote accepted

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/ docky
share|improve this answer
Fiksdal : As we talked about it a few minutes ago ... please give this solution a try - it most probably will solve your problem ... +1 ! :) – cl-netbox Mar 29 at 13:26
@cl-netbox it did :) – Fiksdal Mar 29 at 13:46
@Fiksdal always glad it works :) – Jacob Vlijm Mar 29 at 13:47

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.

share|improve this answer
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. – bc2946088 Mar 29 at 12:49
@MRX The other answer worked perfectly, so I don't see any reason to try this. – Fiksdal Mar 29 at 13:47
Almost certainly, this will break from cron like this, since you need the DISPLAY -variable on GUI stuff. – Jacob Vlijm Mar 29 at 14:42
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 at 14:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.