My Script For Process Checking is NOT Working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting My Script For Process Checking is NOT Working
# 8  
Old 04-24-2012
Quote:
Originally Posted by rymnd_12345
[...]
So what I've did is to have it this way:
Code:
psef=`ps -ef | grep "IP-PoolSession-Summary.sh" | grep -v "grep" | wc -l`
if [ $psef -ge 3 ]; then
[...]

and it worked... don't know why it behaved that way.
This should work fine if you're sure that your script will always be executed with bash
(and - really less likely to happen - that the name of the script will never appear in the process list for some other reason).

You may implement a lock/flag file like this:

Code:
_lock_dir=<some_lock_dir>
_lock_file=${0##*/}.lck

[ -f "$_lock_dir/$_lock_file" ] && [ ! -L "$_lock_dir/$_lock_file" ] && {
  printf >&2 'another instance of %s is already running: $s\n' "${0##*/}" "$(< "$_lock_dir/$_lock_file")"
  exit 1
  }

[ -d "$_lock_dir" ] || 
  mkdir "$_lock_dir" || {
    printf >&2 'failed to create lock dir: %s\n' "$_lock_dir"
    exit 1
    }

printf > "$_lock_dir/$_lock_file" '%d\n' $$

<the rest of your code here ... >

# remove the lock file at the end

[ -f "$_lock_dir/$_lock_file" ] && [ ! -L "$_lock_dir/$_lock_file" ] &&
  rm -- "$_lock_dir/$_lock_file" || {
    printf >&2 'failed to remove lock file: %s\n' "$_lock_dir/$_lock_file"
    exit 1
    }

1. In the above demo I'm using some constructs that are not available in the old (the traditional) Bourne shell (the parameter expansion).
2. In one place I'm using a non standard (not POSIX) syntax, but that construct is available in most modern shells.

Let me know if that's a problem for you.
# 9  
Old 04-24-2012
Hi radoulov,

Thanks dude!


ULF, Thank you all! Til next time Smilie



BR,
Raymond
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking DataPump Process

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)
Discussion started by: pvmanikandan
1 Replies

2. Shell Programming and Scripting

Problem with a script for checking the state of a process

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)
Discussion started by: adilyos
3 Replies

3. Solaris

Python script not working in batch process

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)
Discussion started by: mhahe
1 Replies

4. AIX

Script Checking LVM Mirror not Working

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)
Discussion started by: fede_mont
5 Replies

5. Shell Programming and Scripting

block process checking

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)
Discussion started by: learnbash
3 Replies

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

7. Shell Programming and Scripting

The checking of folder existance is not working...

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)
Discussion started by: suigion
1 Replies

8. Shell Programming and Scripting

Checking for multiple instances of a process

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

9. Shell Programming and Scripting

Checking the cron process in unix

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)
Discussion started by: Ashok_oct22
2 Replies

10. HP-UX

checking process existed

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)
Discussion started by: Frank2004
5 Replies
Login or Register to Ask a Question