Sponsored Content
Top Forums UNIX for Advanced & Expert Users How to prevent job1 from running while job2 is running.. Post 302088731 by blowtorch on Thursday 14th of September 2006 05:40:13 AM
Old 09-14-2006
Code:
# cat one.sh
#!/bin/ksh

if [ -f /tmp/lockfile ]; then
        exit
fi
touch /tmp/lockfile
echo "Process one doing work..."
sleep 10
echo "Process one completed work..."
rm /tmp/lockfile
# cat two.sh
#!/bin/ksh

if [ -f /tmp/lockfile ]; then
        exit
fi
touch /tmp/lockfile
echo "Process two doing work..."
sleep 10
echo "Process two completed work..."
rm /tmp/lockfile
# ./one.sh &
[1] 7377
# Process one doing work...

# ./two.sh
# ./two.sh
Process one completed work...
# ./two.sh
Process two doing work...
Process two completed work...
#

As you can see, process two, didn't start as long as process one was running.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

My script is not running

I have wriiten the following scripts in UNIX. The file name is bk.ksh rman target=/ << EOF RUN { SHUTDOWN IMMEDIATE STARTUP MOUNT ALLOCATE CHANNEL ch1 device TYPE DISK FORMAT '/u01/oradata/ora/%U'; BACKUP DATABASE PLUS ARCHIVELOG; SQL'ALTER DATABASE OPEN' ;} EXIT; EOF when i try... (8 Replies)
Discussion started by: manna
8 Replies

2. Solaris

Running from Shell Vs running from RC script

Hi, i have a script which need to do behave differently when run as a startup process from init.d/ rc2.d script and when run manually from shell. How do i distinguish whether my script is run by init process or by shell?? Will the command /proc/$$/psinfo | grep "myscript" work well???... (2 Replies)
Discussion started by: vickylife
2 Replies

3. Programming

defunct vs running

hello everybody! Is there any way to identify if a process is defunct or if it is still running? (in C). for example: by using a signal such as SIGCHLD? thanx in advance (1 Reply)
Discussion started by: nicos
1 Replies

4. UNIX for Dummies Questions & Answers

too many inetd running

hi, is it ok for more than one inetd daemon running at a time? if not okay, possible to kill the rest and make only one daemon running? i understand that inetd is a process that enables tcp connections from external sources...kindly advise more on inetd...thanks alot..Happy New Year!:) (2 Replies)
Discussion started by: cromohawk
2 Replies

5. Shell Programming and Scripting

Running Total Running Wild

Hi. A shell scripting newbie here. I am trying to write a script that will create a running total of Sales, and increment a counter for each Sales entry, but when I executed the program it never stopped. counter=0 Sales=0 echo "enter sales price" read sales while do let counter=counter+1... (6 Replies)
Discussion started by: Ccccc
6 Replies

6. Shell Programming and Scripting

prevent running of duplicate scripts

i have a script tool.sh,but i want to include a script within it that checks if tool.sh is already running,if already running then the new one called should exit,but if not then the new one should proceed and run. i want to prevent the duplicate running of the script. (5 Replies)
Discussion started by: tomjones
5 Replies

7. AIX

AIX - "prevent script from running twice" issue

I know about standard "ps ..|grep .. | grep -v grep" solution, but... this is different issue I have encountered in several companies I worked for. And I see this only for AIX - not HP, not Solaris, not Linux. Korn shell script is scheduled in the background (via cron /via Tivoli Scheduler or... (6 Replies)
Discussion started by: ooops
6 Replies

8. Shell Programming and Scripting

Cron job running for some days and is not running for some days

Hi.. i have written a shell script and made this script to run on every day night 11: 55 pm using a cron job. This cron job running for some days and is not running for some day. but i need this script to run every day night. Please help me. Here is the cron tab entries, 55 23 * * *... (1 Reply)
Discussion started by: vidhyaS
1 Replies

9. Shell Programming and Scripting

Why script is running sometimes and not running sometimes?

Hi, I have a script which does couple of database connection and run some SELECT queries to get some output in the file. I am surprised to see :eek: that when i run my script some times it gives the desired out put and sometimes it shows some error :confused: . Suppose if i execute it say... (3 Replies)
Discussion started by: Sharma331
3 Replies

10. UNIX for Beginners Questions & Answers

Script not running

hi i have a alarm file mentioned as below alarm_log.15122017 i want to fetch failure detail but script is not working . kindly let me now where is the mistake #!/bin/bash cd /scripts/ DATE=`date "+ %d%m%Y"` ls -lrt | grep -i "alarm_log.$DATE" cat alarm_log.$DATE |grep -B 1... (6 Replies)
Discussion started by: scriptor
6 Replies
SHLOCK(1)						    BSD General Commands Manual 						 SHLOCK(1)

NAME
shlock -- create or verify a lock file for shell scripts SYNOPSIS
shlock [-du] [-p PID] -f lockfile DESCRIPTION
The shlock command can create or verify a lock file on behalf of a shell or other script program. When it attempts to create a lock file, if one already exists, shlock verifies that it is or is not valid. If valid, shlock will exit with a non-zero exit code. If invalid, shlock will remove the lock file, and create a new one. shlock uses the link(2) system call to make the final target lock file, which is an atomic operation (i.e. "dot locking", so named for this mechanism's original use for locking system mailboxes). It puts the process ID ("PID") from the command line into the requested lock file. shlock verifies that an extant lock file is still valid by using kill(2) with a zero signal to check for the existence of the process that holds the lock. The -d option causes shlock to be verbose about what it is doing. The -f argument with lockfile is always required. The -p option with PID is given when the program is to create a lock file; when absent, shlock will simply check for the validity of the lock file. The -u option causes shlock to read and write the PID as a binary pid_t, instead of as ASCII, to be compatible with the locks created by UUCP. EXIT STATUS
A zero exit code indicates a valid lock file. EXAMPLES
BOURNE SHELL #!/bin/sh lckfile=/tmp/foo.lock if shlock -f ${lckfile} -p $$ then # do what required the lock rm ${lckfile} else echo Lock ${lckfile} already held by `cat ${lckfile}` fi C SHELL #!/bin/csh -f set lckfile=/tmp/foo.lock shlock -f ${lckfile} -p $$ if ($status == 0) then # do what required the lock rm ${lckfile} else echo Lock ${lckfile} already held by `cat ${lckfile}` endif The examples assume that the file system where the lock file is to be created is writable by the user, and has space available. HISTORY
shlock was written for the first Network News Transfer Protocol (NNTP) software distribution, released in March 1986. The algorithm was sug- gested by Peter Honeyman, from work he did on HoneyDanBer UUCP. AUTHORS
Erik E. Fair <fair@clock.org> BUGS
Does not work on NFS or other network file system on different systems because the disparate systems have disjoint PID spaces. Cannot handle the case where a lock file was not deleted, the process that created it has exited, and the system has created a new process with the same PID as in the dead lock file. The lock file will appear to be valid even though the process is unrelated to the one that cre- ated the lock in the first place. Always remove your lock files after you're done. BSD
June 29, 1997 BSD
All times are GMT -4. The time now is 04:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy