How to check if the script is already running?

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to check if the script is already running?
# 8  
Old 01-31-2017
Quote:
Originally Posted by thomasraj87
@vgersh99, Will it kill the existing process that were running the script already?

@Corona688, According to my script i have to redirect the various output to different files, so i have given the logfiles name explicitly. I will consider to use $$ PID in my logfiles.
When multiple files are involved I often do /tmp/$$-loggerdata, /tmp/$$-output2, and so forth. Don't forget to delete them when no longer needed or you'll have a mess.

This would be far better than just making exclusion, you'll be improving the usability of your program and removing a lot of potholes.
# 9  
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question