Good day! Just want to share my code and as well as my problem on why I'm not getting the output that I want. My original code was:
Now since this script can be used by other users, there will be a possibility of having simultaneous running-process for this script which will lead to a wrongly data to be parsed, so in order for this one not to happen, I want to check if the process is running it will prompt the user that it's not yet safe to run the script otherwise begin using it. So I've decided to put something like this into my code:
The problem with this code is that it's not prompting the user and still continues and proceed with the original code (which is after the else function) even if I already ran one before running it again.
Then I've modified the if/else by doing something like this:
As you can see, I've just changed the if/else to if/elif, but again the output is that after executing the script, it automatically exits. No prompt appeared even.
Can you please help me with this problem? I'm working on a SUSE Linux.
Thanks and Best Regards,
rymnd_12345
Last edited by rymnd_12345; 04-24-2012 at 04:56 AM..
Reason: typo error
Try printing the output of the ps command at the beginning of your script:
You'll see the current instance of your script.
Than try to invoke the script like this and compare the output:
To elaborate further: you cannot only check the presence of your script in the process list for obvious reasons: your script
is running when you're running the ps .. | grep .. pipeline, so this thest will always return true.
If you count with ps .. | grep -c .. the output will depend on the shell implementation
(some shells thread differently the last command in a pipeline).
So, again, for a more robust solution, I'd suggest the implementation of some
locking mechanism.
Assuming that the script containing the duplicate session test is called IP-PoolSession-Summary.sh then surely one copy running is not a problem ($psef -eq 1). The second and subsequent copies are a problem ($psef -ge 2). Don't forget to count the script you are running the test from!
I too recommend using flag files. The output from ps is not reliable enough for this type of processing.
How is it? about the locking mechanism? How to do it?
Hi methyl,
I've tried simulating it, and still it returned the error prompt even without running the script yet, then I noticed that as if it includes the count of the
still. So what I've did is to have it this way:
and it worked... don't know why it behaved that way.
Thanks for all you input.
Still expecting for a better solution like locking mechanism though.
Hi All,
I am writing script for Env refresh for Oracle DB. I am using Datapump for that. If i start expdp or impdp, how can i know that export or import has completed. I have query for that. How will i integrate with script?. Or any command i can run from Linux side. Please share you... (1 Reply)
Hello Everyone,
I have a process that should be always running. Unfortunately, this process is getting down almost every 10 minutes. I want to make a script that verify the state of this process: If the process is up, the script shouldn't do nothing and if it's down he should run it.
Can... (3 Replies)
Good morning, I have a python 2.3 script that runs stand alone as intended when tested, then it was put into a ksh script. when running the ksh script it runs as intended. The problem is that my script does not run when the ksh script is called by another user who runs a batch process (as of right... (1 Reply)
Hi,
I need to know who can I create an script in order to check server mirror in AIX. I got this script
!/usr/bin/ksh
#
# Check if a VG is mirrored.
#
# lsattr -El <lvname> -a strictness -a copies
# If copies=2 and scrictness=y, then VG is mirrored
#
# LVs are retrieved via 'lsvg -l... (5 Replies)
How can i check block process in Linux?
If found any what action is required?
How to check the pid of process?
How to kill the block process?
How to find out bottleneck process? (3 Replies)
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)
Hi all,
I have the following code:
if ; then echo 'folder not exist'; else echo 'folder exist'; fi
The "testing" folder is not exist in /home/batch , but thhe result is 'folder exist'. It seems that the code cannot detect that the folder "testing" not exist.
ANybody know the... (1 Reply)
Hi
I have a scenario where i need to check multiple instances of a running shell script (abc.sh) .
How can I find from inside a running shell script whether any other instance of the same script is running or not? If any other instance of same shell script is running I need to exit from... (4 Replies)
Hi Experts,
Is there any command by which i can chk that the cron process is running fine? Say i have scheduled the cron to run at 10 o clock every monday,Do i need to wait for the time it runs and then chk using ps -ef?
Please shed some light.
Thanks
Ashok. (2 Replies)
On HP-UX, in application, if the process id has been get with the getpid() and sotred in database, then other monitor process want to check it if the process is existed, are there any system function can do it? I do not want to use the shell script, because it should use popen function to excuted... (5 Replies)