process control

From: Leiji Liu (leijiliu_at_nexrain.com)
Date: 07/30/03


Date: Wed, 30 Jul 2003 21:57:47 GMT

Hi,

I have a piece of script which runs periodically from cron table. In order
to prevent the second copy of the same code from running simultaneously, I
have to "ps" the current status of memory and if there is one copy running,
the second will not start. A guru gave me following piece (on Solaris
system):

The script's name is "allrun.sh".

#!/bin/ksh
check=`ps -ef |grep "/bin/ksh /home/mycode/allrun.sh" | wc -l`
if [ $check = 2 ] ; then
    process my programs
fi

Here is the question. Why should the $check be 2? Or should it be better
$check < 2? When I manually start "allrun.sh" (not from cron table) from
command line, the $check is 0. Can anybody give me some explanation?

Thanks a lot!

ll



Relevant Pages

  • Re: Nmon scheduling question
    ... command ran first then in the script is the ps and kill command so it ... Vince this is a great script. ... Cron Job with pid: 135238 Failed ...
    (AIX-L)
  • SUMMARY: cron entry: nth day of every month?
    ... cron can not handle this with its own syntax. ... 21st but "command" only runs if the output of the "date" command ... What I would suggest is rather than embedding the logic in each script ... The answer is it is _not_ possible to control it only with crontab ...
    (Tru64-UNIX-Managers)
  • Script wont run from cron
    ... the command line, but the same script fails when running from cron. ... The /bin/sh script runs, but when it goes to fire up the indexing process, ... set, id and limits. ...
    (freebsd-questions)
  • Re: Cron Job
    ... If you mean the computer itself, put that command ... The standard 'cron' runs jobs at a specific time/date. ... Init or @reboot run jobs when ... Sunday night at 02:00) then copy the script and cron entry. ...
    (comp.os.linux.misc)
  • Cron entry & .profile question
    ... Cron jobs can be confusing at times. ... When I run a script I wrote from ... The bourne shell uses the command "." ... Should I run my cron job as root or should I make a new cron entry ...
    (SunManagers)