LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 12-09-2003, 12:39 PM   #1
nharnwal
LQ Newbie
 
Registered: Dec 2003
Posts: 1

Rep: Reputation: 0
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?
 
Old 12-10-2003, 08:28 PM   #2
jdc2048
Member
 
Registered: Jul 2002
Distribution: Redhat, Gentoo, Solaris, HP-UX, etc...
Posts: 391

Rep: Reputation: 30
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cp files from grep results Sigkill(9) Linux - Newbie 2 08-22-2005 03:17 PM
Find out heap size for a PID luexiong Linux - General 1 03-29-2005 09:40 AM
how to find all files with pid Zac2003 Linux - Software 2 10-27-2004 09:44 PM
Using the results of locate for grep skibud2 Linux - Newbie 1 12-16-2003 01:58 PM
How to find the pid to stop a process.... vous Linux - Networking 6 08-14-2003 04:18 AM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 08:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration