Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

shlock(1) [bsd man page]

SHLOCK(1)						      General Commands Manual							 SHLOCK(1)

NAME
       shlock - create lock files for use in shell scripts

SYNOPSIS
       shlock -p pid -f name [ -b ] [ -u ] [ -c ]

DESCRIPTION
       Shlock  tries  to  create  a  lock  file named name and write the process ID pid into it.  If the file already exists, shlock will read the
       process ID from the file and test to see if the process is currently running.  If the process exists, then the file will not be created.

       Shlock exits with a zero status if it was able to create the lock file, or non-zero if the file refers to currently-active process.

OPTIONS
       -b     Process IDs are normally read and written in ASCII.  If the ``-b'' flag is used, then they will be written as  a	binary	int.   For
	      compatibility with other systems, the ``-u'' flag is accepted as a synonym for ``-b'' since binary locks are used by many UUCP pack-
	      ages.

       -c     If the ``-c'' flag is used, then shlock will not create a lock file, but will instead use the file to see if the	lock  is  held	by
	      another  program.   If  the  lock  is  valid, the program will exit with a non-zero status; if the lock is not valid (i.e., invoking
	      shlock without the flag would have succeeded), then the program will exit with a zero status.

EXAMPLES
       The following example shows how shlock would be used within a shell script:
	      LOCK=/var/run/innd/LOCK.send
	      trap 'rm -f ${LOCK} ; exit 1' 1 2 3 15
	      if shlock -p $$ -f ${LOCK} ; then
		  # Do appropriate work
	      else
		  echo Locked by `cat ${LOCK}`
	      fi

HISTORY
       Written by Rich $alz <rsalz@uunet.uu.net> after a description of HDB UUCP locking given by Peter Honeyman.  This  is  revision  1.9,  dated
       1996/10/29.

																	 SHLOCK(1)

Check Out this Related Man Page

SHLOCK(1)						      General Commands Manual							 SHLOCK(1)

NAME
shlock - create lock files for use in shell scripts SYNOPSIS
shlock -p pid -f name [ -b ] [ -u ] [ -c ] DESCRIPTION
Shlock tries to create a lock file named name and write the process ID pid into it. If the file already exists, shlock will read the process ID from the file and test to see if the process is currently running. If the process exists, then the file will not be created. Shlock exits with a zero status if it was able to create the lock file, or non-zero if the file refers to currently-active process. OPTIONS
-b Process IDs are normally read and written in ASCII. If the ``-b'' flag is used, then they will be written as a binary int. For compatibility with other systems, the ``-u'' flag is accepted as a synonym for ``-b'' since binary locks are used by many UUCP pack- ages. -c If the ``-c'' flag is used, then shlock will not create a lock file, but will instead use the file to see if the lock is held by another program. If the lock is valid, the program will exit with a non-zero status; if the lock is not valid (i.e., invoking shlock without the flag would have succeeded), then the program will exit with a zero status. EXAMPLES
The following example shows how shlock would be used within a shell script: LOCK=/var/run/innd/LOCK.send trap 'rm -f ${LOCK} ; exit 1' 1 2 3 15 if shlock -p $$ -f ${LOCK} ; then # Do appropriate work else echo Locked by `cat ${LOCK}` fi HISTORY
Written by Rich $alz <rsalz@uunet.uu.net> after a description of HDB UUCP locking given by Peter Honeyman. This is revision 1.9, dated 1996/10/29. SHLOCK(1)
Man Page

15 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how can i create a simple progress bar in shell

please help me as i want to create a simple process bar to check the status for any script......... especially in UNIX (5 Replies)
Discussion started by: aditya.ece1985
5 Replies

2. Shell Programming and Scripting

Stopping A process

Hi I want to stop a process using a shell script. how do i do that? ie, to simulate ps -ef|grep Process name get the process id and kill -9 process id plz help... (4 Replies)
Discussion started by: gopsman
4 Replies

3. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: strunz
4 Replies

4. Shell Programming and Scripting

Checking if a file exists

How can I check if a file exists in shell script. Basically, I want to check if a file Test_msgs has been created today. If it has been then append data to it. Otherwise, create it. I have written the following but it does not work. todaysdate=$(date +%d%m%Y) timenow=$(date +%H%M%S)... (4 Replies)
Discussion started by: gugs
4 Replies

5. Shell Programming and Scripting

Background Process.

How to create a backgrond processes ? (5 Replies)
Discussion started by: anupdas
5 Replies

6. Shell Programming and Scripting

How to write a directory lock shell script?

Hi there, pleas I want this script urgently. how to lock a directory by shell script? (12 Replies)
Discussion started by: joneggk
12 Replies

7. Shell Programming and Scripting

sh: Detect key (CTRL/SHIFT/CAPS LOCK) state?

I'm trying to write a shell script that runs periodically and if I'm not at the keyboard, it should do one thing, but if I am at the keyboard, it should do another thing. Therefore I've decided that it would be good if I could press down the CTRL key, (or some other key) and have the shell script... (8 Replies)
Discussion started by: Ilja
8 Replies

8. Shell Programming and Scripting

Large password lock script

I am trying to create a script that will take a very large, tab delimited file and then lock accounts. File headers look like this id desc server pass sudo lock test Test user server01 67 no no "Test user" is under the desc column Basically if pass column is greater... (5 Replies)
Discussion started by: Gibby13
5 Replies

9. Shell Programming and Scripting

Process checking loop

Hi, I want to create a script who will check if the java process is running & if it finds the process is still there it continues to execute & when the process completes it exit from the script. I have written a code to check & notify the process existence but i am not getting how to write... (4 Replies)
Discussion started by: d8011
4 Replies

10. Shell Programming and Scripting

simple awk problem

Hello; I have the following log file: 10/11/11 10:42:02 LOCK Q Userid:284 Username=root UserPID:23158 Device:marlin batch 10/11/11 10:42:02 TableNr:226 TableName:iatkn RecId:116290398 Flags:X Q H 10/11/11 10:42:02 LOCK CONTENTION X 10/11/11 10:42:02 ... (3 Replies)
Discussion started by: delphys
3 Replies

11. Shell Programming and Scripting

Working on Files

Hi, One of the program creating a file with the following information. $cat a.txt 1, AAA, 234 $ and I wrote a script whenever any of the the file exists with data then it will send a email to me. If I start the job second time, then the as per the logic it is sending the same data, I... (3 Replies)
Discussion started by: Alex_Smith
3 Replies

12. Shell Programming and Scripting

script to remove and recreate a lock file

Hi all, i have a small script to remove locks for the prevous day and create new lock for processing in the path on my server i have made something like this #!/bin/sh #lock_remover #script to remove regular lockfiles and hang curr_month=`date "+%b"` 2day=`date "+%_d"` cd... (4 Replies)
Discussion started by: godie_b_w
4 Replies

13. Shell Programming and Scripting

Help needed to create a UNIX Space monitoring script

Hi All, Its urgent.. pls help me out.. I want to create a KSH which should generate a report with the list of users and the files larger than 5 GB created by them in a direcorty and send autogenerated e-mail to them. my input would be users list,directory path and the file size (say 5 GB) ... (11 Replies)
Discussion started by: anman0523
11 Replies

14. Shell Programming and Scripting

How to check/compare lock file?

Hi all, I have a shell script that I schedule to run from 0700 - 1900, every 15minutes. For each run it creates a lock file and remove it on exit. While there is a bit of a flaw to it where the lock file don't get remove if someone kills the script while it is running, I am fairly satisfied... (6 Replies)
Discussion started by: newbie_01
6 Replies

15. Shell Programming and Scripting

Script to start process

Hi I want to create a script to be able to check if a process is running and act on it. Essentially I want to: Check acc process status /opt/ca/APMCommandCenterController./apmccctrl.sh status If process found not to be running Execute start command... (6 Replies)
Discussion started by: simpsa27
6 Replies