![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to Lock In HP-UX | naren_chella | HP-UX | 7 | 07-07-2006 09:49 AM |
| Lock File | canman | UNIX for Dummies Questions & Answers | 4 | 05-06-2005 06:28 AM |
| host lock up | alex_slb | UNIX for Dummies Questions & Answers | 1 | 06-24-2002 09:23 PM |
| how to lock keyboard without using lock command | dianayun | UNIX for Dummies Questions & Answers | 7 | 06-21-2002 07:05 PM |
| lock file! | sskb | UNIX for Dummies Questions & Answers | 4 | 10-24-2001 06:10 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Lock for this script
Hi,
My requirement is to service a process and below is the script which i wrote for that and works fine, I have kept it in a crontab and running this everyminute, how do I lock this if its already running and i dont want to open if its running and not completed yet. The crontab need to run for the next minute after it completes running the older one. #!/bin/ksh while [ true ]; do i=$(ps -ef | grep PROCESS_NAME |grep -v grep |wc -l) if [ "$i" -lt 2 ] then echo "`date '+%Y-%m-%d-%H:%M:%S'` WARNING !!! PROCESS IS DOWN" else echo "`date '+%Y-%m-%d-%H:%M:%S'` PROCESS IS UP" fi done Help me to keep a lock for this, I am using AIX 5.3 |
|
||||
|
Yeah, what dragon said.
Personally, I like option 3. There's a million ways ya might get it done, but the three suggestions are probably the basis for most of 'em. Keep in mind the potential use of the shell variables $! and $$. $! is the PID of the last process run in the background and $$ is the PID of the script itself. You might use the latter to create more-or-less unique lockfile names (time stamp is probably better for that, actually). Still, they may come in useful as your script matures. Last edited by Lukeadams; 02-19-2008 at 12:28 AM.. |
|
||||
|
Hi all,
Will this work if i keep it in my crontab, please see if any syntax error is there. #!/bin/ksh while [ true ]; do for i=$(ps -ef | grep SCRIPT_NAME |grep -v grep |wc -l) if [ "$i" -lt 1 ] then echo "`date '+%Y%m%d|%H%M%S'` Script Already running!!!" exit 0 while [ true ]; do i=$(ps -ef | grep PROCESS_NAME |grep -v grep |wc -l) if [ "$i" -lt 2 ] then echo "`date '+%Y%m%d|%H%M%S'` WARNING !!! PROCESS IS DOWN" else echo "`date '+%Y%m%d|%H%M%S'` PROCESS IS RUNNING" fi done |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|