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?
