Operating System - HP-UX
1832983 Members
2968 Online
110048 Solutions
New Discussion

Re: cron will start multiple instances of shell scripts within cron

 

cron will start multiple instances of shell scripts within cron

Help!!! HP-UX 10.20 running on K460
We use numerous shell scripts that are running through root's cron. To my horror I noticed cron restarting these scripts even when they are already running. I need them not to restart, if an invokation of that shell script is already running. We are porting code from a Sequoia to HP, Sequoia's Topix OS
will not allow the same script to run out of cron (multiple invokations), HP-UX doesn't care? I find this hard to believe, I'm sure I must be doing something wrong. ANY help is appreciated.
Thanks, Andy
3 REPLIES 3
John Palmer
Honored Contributor

Re: cron will start multiple instances of shell scripts within cron

Hi Andy,

As far as I'm aware, cron doesn't care what is already running.

What I do is to make the script itself ensure that another copy isn't already running.

You can simply count relevant entries from a 'ps' listing or use a more sophisticated locking mechanism.

Regards,
John
Thomas J. Harrold
Trusted Contributor

Re: cron will start multiple instances of shell scripts within cron

Perhaps you can explain what you are trying to accomplish. If you are using cron to ensure that a program/daemon is running (one instance), then simply put some code at the front of your script that checks to see if the process is already running. If the process already exists, exit, otherwise continue and run the process.
I learn something new everyday. (usually because I break something new everyday)

Re: cron will start multiple instances of shell scripts within cron

Like John said, cron does not care, so perhaps you also need to check the intervals at which one cron job is kicked off before the next invocation. Otherwise Thomas's suggestion is the best.

Also check if there are no "at" jobs invoking the same scripts.

Regards

Ish
If you keyboard is locked, call a locksmith, not HP!