Server Fault is a question and answer site for system and network administrators. 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

I guess I could have a cron job run every minute, or 5 minutes, and have it somehow check if the process was already running (not sure how to do that).

Would that be the best way or is there another like .startup script in my home directory that I could put a script in?

share|improve this question
up vote 2 down vote accepted

The issue here seems to be that you don't have root access on this host to change the system startup scripts like /etc/rc.local. The idea of using a @reboot line in your user crontab is worth exploring. I haven't tried that as a normal user but it should work.

The other idea is as you say to run something in your user crontab every few minutes, check if your process is running, and restart if not. For example:

*/5 * * * * ps -u $USER | grep myscript >/dev/null || $HOME/bin/myscript

be very careful with this sort of thing - if you make a mistake you will end up starting an extra copy of your program every 5 minutes which could eventually cause a lot of problems.

share|improve this answer
reboot is only for privileged accounts. adding reboot in a user's crontab will give a permission denied, as crontab runs that command with the user's privilege, not with root. – w00t Jan 28 '11 at 8:00
Yeah that was kinda what I was thinking. Leads to DoS situations and the like. – Phil Hollenback Jan 28 '11 at 8:07
well said - i was not thinking about if they had access or not however... ;-) good catch – Glenn Kelley Jan 28 '11 at 8:56
I had to change grep to grep [m]yscript so that it won't find the grep process, but otherwise this works great. Thanks! – cwd Mar 14 '11 at 16:44

you could use chkconfig - or be lazy and simply just run in your crontab

@reboot command-goes-here

This link may help you a great deal (saves me typing it all out ... of course)

share|improve this answer

Depending on your distribution (you did not mention it), you have a pretty wide area of choice: chkconfig, rcconf, /etc/(rc.d/)rc.local, symlinking startup scripts in init.d\rc.d - but all these require root privilege.

I am assuming you have no access to sudo. These leaves you with just one option, adding a script in crontab that checks if the process is running, and if it not, then start it up. You also gain a kind of availability enhancement (eg. if your process crashes, it is started up again).

My take on this is:


`ps aux > /tmp/.$proc; awk '/$proc/{print $2}' /tmp/.$proc > /tmp/.x` #if process is alive then copy its PID in .x
    if [ -s /tmp/.x ]; then    #-s file True if file exists and has a size greater than zero. 
            echo k   #.x is greater than zero => process is alive, all ok
            /etc/init.d/daemon start _or_whatever_startup file_ #.x was zero, process dead.
`rm -f /tmp/.$proc && rm -f /tmp/.x`
share|improve this answer

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.