![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to get and process mysql result set in shell script | ashok1979 | Shell Programming and Scripting | 4 | 08-03-2009 08:28 AM |
| Shell script to display top 5 process (per cpu consumption) | mr_awd | Shell Programming and Scripting | 2 | 05-26-2009 09:23 AM |
| Shell Script to end process help | NoobieBoobie | UNIX for Dummies Questions & Answers | 6 | 04-06-2009 03:11 AM |
| How can i know file using another process on lunix shell script? | Tlg13team | Shell Programming and Scripting | 1 | 04-02-2007 02:33 AM |
| Shell Script Dependencies other process | pankajkrmishra | Shell Programming and Scripting | 4 | 07-25-2006 05:20 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Getting process ID in a shell script.
Hi all,
In my script i need to store the process ID of my app server in a variable. I know how to verify whether a process is running, by following: Code:
ps -ef|grep 'jboss' status=$? if [ "$status" = 0] ; then # process is running else # process is nor running fi Can someone please advise, how can I get the process ID? Thanks in advance. |
|
||||
|
Thanks Scott, for quick reply,
Here's what I have in my script: Code:
#!/bin/sh
. ~/.profile
PID=$(ps -eo pid,comm | awk '$2 == "jboss" {print $1}')
echo $PID
if [ -z "$PID" ]; then
echo "... not running"
else
echo "... running"
fi
Code:
haroon_a 544950 659604 1 Nov 02 - 8:30 /app/jboss4.2.0/jdk/bin/java -Dprogram.name=run.sh -server -Xms1024m -Xmx1500m -XX:PermSize=64m -XX:MaxPermSize=256m -Xss512k -XX:+HeapDumpOnOutOfMemory -XX:+DisableExplicitGC -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.endorsed.dirs=/app/jboss4.2.0/lib/endorsed -classpath /apps/shared/jboss4.2.0/bin/run.jar:/app/jboss4.2.0/jdk/lib/tools.jar org.jboss.Main -c DctmServer_MethodServer -b 0.0.0.0 Can you comment, please. |
|
||||
|
I don't have jboss running, but if I substitute that for something else then it works fine.
Code:
PID=$(ps -eo pid,comm | awk '/mingetty/ {print $1}')
/home/oracle/tmp > echo $PID
2499 2500 2501 2502 2503
> cat Test
PID=$(ps -eo pid,comm | awk '/mingetty/ {print $1}')
echo $PID
if [ -z "$PID" ]; then
echo no mingetty running
else
echo alles gut!
fi
-----------------------------
> ./Test
2499 2500 2501 2502 2503
alles gut!
Try Code:
PID=$(ps -ef | awk '/jboss/ {print $2}')
if [ -z "$PID" ]; then
echo not running
else
echo is running!
fi
|
|
||||
|
Quote:
That worked! Thanks alot and real appreciate it. ---------- Post updated at 03:32 PM ---------- Previous update was at 03:11 PM ---------- On a seperate note: Now I know how to get the processes for my jboss, and store it in a vriable. I want to issue another ps command on those PIDs of jboss, later on in my script to see if they are still running or not. i.e. Code:
PID=$(ps -ef | awk '/jboss/ {print $2}')
if [ -z "$PID" ]; then
echo not running
else
echo is running!
fi
...
...
# do some other things here...
...
...
# Now i want to issue a ps command on those process IDs stored in $PID, to see if those process are still runnning.
Thanks again. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|