Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to check if the script is already running? Post 302990749 by rbatte1 on Tuesday 31st of January 2017 12:24:11 PM
Old 01-31-2017
For locking across multiple servers with shared storage I would suggest that mkdir is better than a simple file creation because of the race condition that would leave. A mkdir will either work (return code zero, it did not exist and I created it) or fail (return code 1, it already exists or I cannot create it for some other reason)

The problem you have of cancelling or suspending a job is going to be a tough one to crack. If someone suspends their job for a long time and then re-enables it, you would expect that instance not to be getting confused by other requests, after all it was able to create the lock (however you did this)

You could, I suppose, disable interrupts with stty -isig (not sure if that's quite correct) and put in the trap suggested above, including the EXIT signal (so it cleans up when the script completes or aborts)

You would have to consider what happens if the server crashes and the lock cannot be cleaned up.

I know it sounds a daft question, but what is the conflict between the various servers running this at the same time? I just don't understand the need, so please help me and there may be a better way to organise this.



Kind regards,
Robin
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

check that script is not running twice

using ps -ef | fgrep "ld_data" how do i write a script to check that it didn't already run Thanks (2 Replies)
Discussion started by: Link_02
2 Replies

2. Shell Programming and Scripting

Check if trigger Script is running

HI, I have a script which will be running all the time...it is like a trigger.. wakesup every 10 minutes(trigger.sh) executes, and I want to write another script which monitors this script every one hour and if it finds that trigger script is not running it should start it and exit...and here... (9 Replies)
Discussion started by: mgirinath
9 Replies

3. Shell Programming and Scripting

Running a check platform script

Hi, I want to run a check platform & application script under ksh (Soaris boxes). It runs some commands and it take some time. I want to customize it like that: - output is too big, hence I want some output of the commands to be redirect ed in an output file (or maybe two or three) - not... (4 Replies)
Discussion started by: heartwork
4 Replies

4. UNIX for Dummies Questions & Answers

check user id before running script

I am looking for the syntax to check which ID is executing script.sh. If the the ID, is not user1 then I want the script to exit and return to command prompt, if it is user1, then I want the script to continue. Any help would be greatly appreciate. Thank you. Chris (3 Replies)
Discussion started by: cpolikowsky
3 Replies

5. Shell Programming and Scripting

script to check if another script is running and if so, then sleep for sometime and check again

Hi, I am a unix newbie. I need to write a script to check wheteher another script is still running. If it is, then sleep for 30m and then check again if the script is running. If the script has stopped running then, I need to come out of the loop. I am using RHEL 5.2 (2 Replies)
Discussion started by: mathews
2 Replies

6. UNIX for Dummies Questions & Answers

Help Running a Check in Bash Script

Hey guys, so I wrote a small script that pretty much just takes in two numbers and counts from the first to the second, e.g. unknown-hacker|544> count.sh 1 3 1 2 3 My problem is I want to make it so that if you input invalid parameters, such as non-numerical characters, more than 2... (2 Replies)
Discussion started by: Duo11
2 Replies

7. Shell Programming and Scripting

Script to check running of process

Hi, Can anyone please tell me how to write a shell script to check whether a process if running or not.... if its still running then wait for sometime and if not then run the next query. Also, Under my one main script main.sh I have to run 2 scripts simutaneously which take some time to... (2 Replies)
Discussion started by: lovepujain
2 Replies

8. UNIX for Dummies Questions & Answers

[Solved] How to Check if a script is running?

Hi All, I am new to Unix... Can you please let me know how we can check if a script is running or not on Solaris box? (4 Replies)
Discussion started by: Rahul466
4 Replies

9. Linux

Check up the status of a Script (running or not)

Hello, i allready search on google und here in the local Forum, but can't found something. I need a query in php, that check whether a process (script) is running or not. Like this: php query: /usr/bin/Script01 >> if runnig, then: "Script01 is Online", if not "Script01 is Offline" I... (2 Replies)
Discussion started by: ProTechEx
2 Replies

10. Shell Programming and Scripting

Check to see if script is already running

Happy New Year Is there a quick way to check to see if a script is already running. I want to put in a check in the script to exit, if already running. Currerntly i can only think of doing it the following way. # ps -ef | grep -i 3_HOUSEKEEPING_FFTVTL_TO_FFTDSSU_DUPLICATION.ksh |... (5 Replies)
Discussion started by: Junes
5 Replies
LOCKMAIL(1)						      Double Precision, Inc.						       LOCKMAIL(1)

NAME
lockmail - create mail lock files SYNOPSIS
lockmail [-r] [-t timeout] {lockfile} {program} [argument...] DESCRIPTION
lockmail is a helper utility for working with mailbox files. Mailbox files must be locked to prevent other applications from modifying the mailbox at the same time. Different system use different locking conventions. lockmail uses two of the most common locking mechanisms in use, which should work reliably on most systems. lockfile is the pathname to an existing mailbox file. By default, lockmail tries to lock the mailbox every five seconds (if the mailbox is already locked), and will give up after three minutes. After the mailbox is successfully locked, lockmail runs program as a child process, with any optional arguments. When program terminates, lockmail removes the mailbox lock, and terminates itself. OPTIONS
-r If a regular lock fails, try a read-only lock. Use this option to lock mailbox files in a read-only directory. -t timeout If the lock attempt fails, try again for up to timeout seconds. The actual timeout is rounded up to the next five second interval (a lock attempt is tried every five seconds). DESCRIPTION
This section briefly describes the locking mechanism used by lockmail. lockmail uses three different locking conventions in order to maximize compatibility with other mail software: C-Client folder locks, dot-locks, and file locks. C-Client folder locks Mail software based on the C-Client library creates lock files named /tmp/.dddddd.iiiiii. Here, dddddd and iiiiii are the device number and the inode number of the mailbox file (the st_dev and st_ino fields in the inode), in hexadecimal. If the process ID saved in the C-Client folder lock file is not valid, lockmail concludes that it's a stale lock file, and will remove it. Note A race condition exists where a C-Client process is killed after it creates a lock file, but before saving its process ID in the lock file. The race window is very small, but it exists. The C-Client library does not appear to ever clear out the lock file. lockmail attempts to resolve this race condition by deleting zero-length lock files that are at least five minutes old. dot-locks lockmail also creates, and honors dot-lock files. Dot-lock files are first created as temporary files, then linked to lockfile.lock. The link operation fails if the dot-lock file already exists. lockmail uses an enhanced method of dot-locking, where its process ID, and the name of the server where lockmail is running is also saved in its dot-lock file. If the operation fails due to an existing dot-lock file that was created by another lockmail process on the same server, and the process ID no longer exists, this stale dot-lock file is removed immediately. In all other situations a dot-lock file older than five minutes is considered stale, and removed. Note A failure to create a dot-lock file is silently ignored if the reason for the failure is because lockmail does not have the write permission in the dot-lock file's directory. The incoming mail spool directory (usually /var/mail) typically does not have global write permissions, so the attempt to create the dot-lock file in the spool directory will fail, and lockmail will be content with using file-locking only. File locks The final locking mechanism lockmail uses is the operating system's file locking facility. If lockmail fails to obtain all three locks, lockmail will sleep for five seconds and try again. The only exception is a failure to create a dot-lock because of no write access to the dot-lock file's directory, which is ignored. If lockmail still fails to obtain all required locks in the amount of time specified by the -t option (or its default value), lockmail will terminate with the EX_TEMPFAIL exit code. lockmail runs program after obtaining the last file lock, waits until program terminates, and releases all locks. program must terminate before any of the locks obtained by lockmail expire, and are considered stale. lockmail will then terminate with the same exit code as program. EXIT STATUS
lockmail terminates with the same exit status as program lockmail terminates with the EX_TEMPFAIL exit status if it was unable to obtain a lock, or if program was killed by a signal. SEE ALSO
maildrop(1)[1], sendmail(8). AUTHOR
Sam Varshavchik Author NOTES
1. maildrop(1) [set $man.base.url.for.relative.links]/maildrop.html Courier Mail Server 08/30/2011 LOCKMAIL(1)
All times are GMT -4. The time now is 10:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy