Verifying a program is running by cron job, if not starting it.
Like the title says I have a program that I want to make sure is running 24/7. Every hour I want to "check" if it is running using a cron job, and if so then nothing, but if it isn't then I want to start it. Currently I have it setup using this command:
/home/username/public_html/loca/locb/sc_trans_linux and you can of course guess the problem... I had 20 processes of the same thing running in no time :) So how can I do it so it only starts an instance if there isn't one running already ? -------- AsstInterests WIPR : nyc01.egihosting.com:6336 |
Code:
[ "$(/sbin/pidof myprocessname)" ] || command_if_not_running.sh |
Another option is to start your process from inittab with respawn action.
|
Quote:
Code:
[ "$(/sbin/337)" ] || /home/username/public_html/loca/sc_trans_linux /bin/sh: /sbih/337: Not a directory |
Quote:
|
pidof is a real program, the point is to get all pids for the named process, which is it is not running, will be null.
|
Quote:
|
Hmmm keeps creating a new process. So I end up with 2 or more processes.
|
i'd have to assume a typo... check that this has the same effect for you:
Code:
[root@kermit ~]# [ "$(/sbin/pidof bash)" ] || echo BASH IS NOT RUNNING! |
All times are GMT -5. The time now is 06:51 PM. |