LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Solaris / OpenSolaris (https://www.linuxquestions.org/questions/solaris-opensolaris-20/)
-   -   Please help - Unpridictable results from grep/ps to find pid (https://www.linuxquestions.org/questions/solaris-opensolaris-20/please-help-unpridictable-results-from-grep-ps-to-find-pid-124267/)

nharnwal 12-09-2003 12:39 PM

Please help - Unpridictable results from grep/ps to find pid
 
I have a shell script which runs in KSH. The script is used to check the process status running or not runing and print the PID, username, start date and time.

OS = SunOS 5.8 Generic_108528-16 sun4u sparc SUNW,Ultra-Enterprise

The script is as follows -
------------------------------------------------------------------------
SHELL=/bin/ksh
SCRIPT_RUN_MODE=file

MODULE=$1
module_pid=""
user=$2
startTime=""
/usr/ucb/ps auxwwwww | grep "${MODULE}" | /usr/xpg4/bin/grep -w ^${user} |grep -v 'grep'| read user module_pid val0 val1 val2 val3 startTime va
l5 val6


if [ -z $module_pid ]; then
echo "No ${MODULE} found running on ${user} account."
else
echo "${MODULE}[PID=${module_pid}] found running on ${user} account for $startTime Hrs."
fi
------------------------------------------------------------------------

Scenario = There are many users (different UNIX accounts) running same commands. The script runs to find the process is up under particular account. A master script calls the above-mentioned script for checking 10 processes status. The processes are java command with runtime parameters and very long classpath. This script runs fine but some time it misses the to catch some processes PID, something goes wrong with "ps" or "grep" or "read". This gives unreliable result.

Can some one please explain the reason?
:scratch:

jdc2048 12-10-2003 08:28 PM

You may want to edit your post and put the script in code brackets. It helps with formatting and shows characters better.

As a response to your question, how long of a classpath do you mean by "very long classpath". Is it possible that the system is cutting off the commands + args at some number (perhaps 256) and therefore sometimes you get what you are looking for & sometimes you don't?

I don't have my system up right now to try your script out, but something someone recently pointed out to me might be useful. You can use the "-o" option with the standard ps command (not sure about the /usr/xpg4/bin/grep though). Then you can get just the fields you want. Play with and see what you come up with.


All times are GMT -5. The time now is 05:46 AM.