Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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

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 11 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/process_monitor.sh docky
share|improve this answer
1  
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
1  
@cl-netbox it did :) – Fiksdal Mar 29 at 13:46
2  
@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
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. – 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
1  
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
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 at 14:53

Your Answer

 
discard

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.