[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] Quick Bail



A short one-liner to keep a script from executing more than one at a time (say a long running script kicked off from cron every minute that runs more than a minute occasionally...

 

my @ps = `ps -ef | grep $0 | grep -v grep`; exit if ( @ps > 1);

 

and a more advanced version...

 

my @procs = grep /perl .*invan\.pl/, `ps axw`; 

if (@procs > 1) { 

   unless ($ENV{USER} eq "jhannah") {  # Hopefully that dork knows what he's doing, so let him do whatever. 

      die "Looks like I'm already running. I refuse to run on top of myself.\n @procs";

   }

 

 

 

Kenn Thompson

Omni Hotels Reservation Center

Sr. Programmer/Analyst
w:402.952.6521
c:402.598.8818

Omni Hotels is proud to be ranked “Highest in Guest Satisfaction Among Upscale Hotel Chains” in the J.D. Power and Associates 2005 North America Hotel Guest Satisfaction StudySM

(Study based on 37,471 responses from guests who stayed in a hotel between December 2004 and May 2005.  Fourteen upscale hotel chains were ranked in the study.  www.jdpower.com)