Why is the 'sh -c' entry getting displayed in ps -ef ? Is there anyway to avoid the 'sh -c' entry from the output of 'ps -ef' ?
I could always use 'grep -v "sh -c"', but I am looking to avoid grep.
Your "grep ksh" is finding the string "ksh" in the name of the script.
If you are trying to prevent two occurances running at the same time, this is better achieved by using a flag file. Beware that the unix "ps" command can sometimes miss processes if the kernel is under stress.
So if flag file the only option I can look forward to ?
Please suggest if there is any other option along with ps that will prevent 'sh -c' from being fetched..
Use the uname -a command and blot anything confidential like computer names with X's.
Interrogating "ps -ef" with "grep" is not the best way to determine if another instances are running (and it is unreliable). Use semaphore files.
In your context if you really want to use ps , then ps -fu<username> reduces the possibilities for mismatches (but sometimes ps will still omit processes).
Ps. The simple answer to your question is to use grep -v but you have rejected this for some reason.
In the semaphore method, the script first checks for the presence of a semaphore file and exits if the file is present. If the file is not present the script immediately creates the semaphore file and subseqently deletes the semaphore file on exit.
Some people call this an interlock file (or even a mutex).
This semaphore file also gives you a reference for when the script started so a monitoring process could detect an overrunning process.