I would have thought that the first command would have work or shouldn't it?
It should - e.g. this works on ksh 93s+ (RHEL):
However, I'm a bit confused about what you're trying to do? All that will get you is a list of (the same) PPID - which you already know...
Depending on your system, you may be able to just do ps -ef $PID
If not, when you're using awk anyway, you might as well use awk to do the entire statement. You can do powerful things with very simple awk statements.
This should print the entire matching line.
There is much variation in the output format for "ps -ef" .
Please post what Operating System and version you have, the Shell (e.g. bash, ksh, sh etc.) and a sample of a few relevant lines from:
The "egrep" for "PID" is just to get the column headings for this example and nothing to do with your variable called $PID.
I can't see anything wrong with the syntax of the first example you posted. Had you used the reserved variable name $PPID that would give trouble in many shells (notably bash).
The way your script behaves makes me wonder if your version of "ps", "awk" or Shell is changing the value of ${PID} (but not when it is a parameter to a sub-shell).
It should - e.g. this works on ksh 93s+ (RHEL):
However, I'm a bit confused about what you're trying to do? All that will get you is a list of (the same) PPID - which you already know...
Hi,
Thanks for your response. What am trying to do is looking for how many defunct processes are from an existing process ID.
We are using Oracle Enterprise Manager (OEM) which is an Oracle product used for monitoring Oracle databases. OEM uses what is called an agent. For some reason, when the agent starts, after a few days, some of the processes that it spawns becomes DEFUNCT when they shouldn't be. All these DEFUNCT processes has their PPID equal to the PID of the agent.
What am trying to do is write a script how many of such processes are DEFUNCT and if I have more than five (5) that means it is going to generate a file handles exhausted error in which case we have to re-start the agent.
Am wanting to grep using "^${PID}$" because sometimes there are some defunct process that are not spawned by the agent.
Example as below:
Am trying to exclude defunct processes where PPID = 24935 or something similar which is why am wanting to make "^${PID}$" works. ${PID} is actually the PPID 'coz am using ps -ef | awk '{ print $3 }'
Hope it's clear what am trying to do.
---------- Post updated at 06:04 AM ---------- Previous update was at 05:58 AM ----------
Quote:
Originally Posted by methyl
There is much variation in the output format for "ps -ef" .
Please post what Operating System and version you have, the Shell (e.g. bash, ksh, sh etc.) and a sample of a few relevant lines from:
The "egrep" for "PID" is just to get the column headings for this example and nothing to do with your variable called $PID.
I can't see anything wrong with the syntax of the first example you posted. Had you used the reserved variable name $PPID that would give trouble in many shells (notably bash).
The way your script behaves makes me wonder if your version of "ps", "awk" or Shell is changing the value of ${PID} (but not when it is a parameter to a sub-shell).
If you are on Solaris use "nawk" not "awk".
What are you actually trying to do?
Hi,
Thanks for your response. What am trying to do is looking for how many defunct processes are from an existing process ID.
We are using Oracle Enterprise Manager (OEM) which is an Oracle product used for monitoring Oracle databases. OEM uses what is called an agent. For some reason, when the agent starts, after a few days, some of the processes that it spawns becomes DEFUNCT when they shouldn't be. All these DEFUNCT processes has their PPID equal to the PID of the agent.
What am trying to do is write a script how many of such processes are DEFUNCT and if I have more than five (5) that means it is going to generate a file handles exhausted error in which case we have to re-start the agent.
Am wanting to grep using "^${PID}$" because sometimes there are some defunct process that are not spawned by the agent.
Example as below:
BTW, didn't know there is a reserved variable named PPID.
Please post what Operating System and version you have, the Shell (e.g. bash, ksh, sh etc.).
In most Shells $PPID is the PID of the process which invoked the current Shell. In bash Shell this environment variable is write protected.
Oracle needs substantial unix kernel tuning. The kernel parameter "maximum number of files open by any one user" is as important as "maximum number of files open on the system" and "maximum number of files locked on the system".
There are detailed kernel tuning guides from Oracle for each O/S, but there will still be more tuning depending on the application.
Getting "defunct" processes from an Oracle client-server application is nothing unusal and the Operating System should clear them up within an hour or so. They are commonly caused by people clicking "X" in a Windows client instead of doing a proper application logout. If they persist for longer this can be because of an application error or because they are stuck when accessing broken hardware.
Depending on your circumstances you may need to tune the unix kernel to allow for as many as double the Oracle clients you actually expect ... or more.
Hi,
If I hard code a value in the grep it works fine from script, when I use variable it doesn't work. On a seperate note, some lines (during testing) works fine from command line but not from scirpt.
#!/bin/bash
# Will fetch the (oldest - as ls will sort by name by default)Date in the... (7 Replies)
Hi Guys,
I'm trying to write an script that will be launched by a user. The script will look at a log file and check for alerts with the date (supplied by user) and a machine's hostname (also supplied by the user). I'm trying to get the output formatted just like the log file.
The logfile looks... (5 Replies)
Hi,
I tried to grep ".sh_history" (DOTsh_history) file and did not return anything though I found the word in .sh _history file through vi editor in Linux. Then I tried to grep ".profile" to check if it is the prob with hidden files and I got results.
Then I verified the same with my friend... (4 Replies)
This is driving me crazy, and I'm hoping someone can help me out with this. I'm trying to do a simple while loop to go through a log file. I'm pulling out all of the lines with a specific log line, getting an ID from that line, and once I have a list of IDs I want to loop back through the log and... (2 Replies)
This script is supposed to find out if tomcat is running or not.
#!/bin/sh
if netstat -a | grep `grep ${1}: /tomcat/bases | awk -F: '{print $3}'` > /dev/null
then
echo Tomcat for $1 running
else
echo Tomcat for $1 NOT running
fi
the /tomcat/bases is a file that... (2 Replies)
Hello,
I'm writing a script that will automate the launch of some services on my AIX machine. However, some services are dependent on the successful startup of others. When I start these services manually, I usually just check a log file until I see a message that confirms a successful... (3 Replies)
I have a file that is 20 - 80+ MB in size that is a certain type of log file.
It logs one of our processes and this process is multi-threaded. Therefore the log file is kind of a mess. Here's an example:
The logfile looks like: "DATE TIME - THREAD ID - Details", and a new file is created... (4 Replies)
Hello, this is probably another really simple tasks for most of you gurus, however I am trying to make a script which takes an input, greps a specific file for that input, prints back to screen the results (which are directory names) and then be able to use the directory names to move files.... (1 Reply)
I have, say, a dozen files, and I want to grep for a string of text within them. I don't remember the exact syntax, but let me give it a shot and show you an idea here...
find . -type f -exec grep thisword {} \;
...and there's a way to put more than one grep into the statement, so it will tell... (1 Reply)