Script to check status of a PID


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to check status of a PID
# 8  
Old 10-03-2006
how would i be able to just verbose the first line of this output... I have the ptree showing the parent/child processes... I want it to print just the parent..which seems to be the first line in the output

bash-3.00# ptree |grep [h]ttpd |grep -v grep |awk '{print $1}'
21679
21680
21681
21682
bash-3.00#
# 9  
Old 10-03-2006
Code:
ptree |grep [h]ttpd |grep -v grep |awk '{print $1}' | sed q

or
Code:
ptree |grep [h]ttpd |grep -v grep |awk '{print $1}' | head -1

# 10  
Old 10-03-2006
Quote:
Originally Posted by zeekblack
how would i be able to just verbose the first line of this output... I have the ptree showing the parent/child processes... I want it to print just the parent..which seems to be the first line in the output

bash-3.00# ptree |grep [h]ttpd |grep -v grep |awk '{print $1}'
21679
21680
21681
21682
bash-3.00#
Which grep are you using ? See if you have the -m flag.

Try this.

Code:
ptree |grep -m 1 "[h]ttpd" |awk '{print $1}'

The second "grep -v grep" is a wasted call. Why ? Because, grep "[h]ttpd" does the same thing as grep httpd | grep -v grep
# 11  
Old 10-03-2006
Quote:
Originally Posted by vino
Which grep are you using ? See if you have the -m flag.

Try this.

Code:
ptree |grep -m 1 "[h]ttpd" |awk '{print $1}'

The second "grep -v grep" is a wasted call. Why ? Because, grep "[h]ttpd" does the same thing as grep httpd | grep -v grep

I tried that...did seem to like that one

bash-3.00# ptree |grep -m 1 "[h]ttpd" |awk '{print $1}'
grep: illegal option -- m
Usage: grep -hblcnsviw pattern file . . .
bash-3.00# pwd
/
bash-3.00# $PATH
bash: /usr/sbin:/usr/bin:/usr/local/: No such file or director
# 12  
Old 10-03-2006
Quote:
Originally Posted by Glenn Arndt
Code:
ptree |grep [h]ttpd |grep -v grep |awk '{print $1}' | sed q

or
Code:
ptree |grep [h]ttpd |grep -v grep |awk '{print $1}' | head -1

Thanks a bunch Glen....just what the doc ordered Smilie

bash-3.00# ptree |grep [h]ttpd |grep -v grep |awk '{print $1}'
21679
21680
21681
21682
bash-3.00# ptree |grep [h]ttpd |grep -v grep |awk '{print $1}' | head -1
21679
bash-3.00#
# 13  
Old 10-03-2006
ok, so this is how far i've gotten so far....the trying to get the script to check if the PID of the httpd process exists...if it does not..send a email stating so. If the HTTPD process does exist, I want it to continue further and do URL state check, if the URL is not responding. I want the script the kill the process and restart it. So far this is what I got...errors..ha

bash-3.00# cat url_check.ksh
#!/bin/ksh
#
# Check to see if URLs respond in a given time period
#
sleeptime="30"
timeout="15"
BASE_DIR="/local/apps/adminutils"
WGET="$BASE_DIR/bin/wget"
DAT_FILE="$BASE_DIR/etc/url_check.dat"
MAIL_LIST="testuser1@testnet.com"
MAIL_LIST2="testuser2@testnet.com"
DEPLOYSTART="/local/apps/WebSphere6/IHS/0/w6u/ihst.sh ws1 start"

#----------------------------------------------------------------------------------------------------------------------------------------------------
# Check for support script
if [ ! -x $WGET ]; then
echo "ERROR Unable to execute $WGET"
fi
#----------------------------------------------------------------------------------------------------------------------------------------------------



#-----------------------------------------------------------------------------------------------------------------------------------------------------
#Below checks for the DeployDirector PID, if it exits it continues to the website status check. dIf not, then it will send an email alert to the MAIL_LIST2 support group stating the daemon is down
#PID=`/usr/ucb/ps -auxwww |grep -i [h]ttpd |grep -v grep | awk '{print $1}'`
PID=`ptree |grep [h]ttpd |grep -v grep |awk '{print $1}' | head -1` > /dev/null
if [ -z "$PID" ] ; then
echo "DeployDirector Server Process PID Is Down." | mailx -s "DeployDirector Server Daemon is DOWN, this may be due to scheduled maintenence by the SA Support group. Confirmation is needed." "$MAIL_LIST2"
else

for url in `cat $DAT_FILE | grep -v "^#"`
do
$WGET -T $timeout -t 1 -q -O /dev/null ${url}
if [ $? -gt 0 ] ; then
/bin/sleep $sleeptime
$WGET -T $timeout -t 1 -q -O /dev/null ${url}
if [ $? -gt 0 ] ; then
# it's still down, still cannot access the URL - we've got a problem!!

kill -9 $PID && $DEPLOYSTART


echo "${url} cannot be accessed. (2 attempts, ${sleeptime} seconds between each attempt, ${timeout} second timeout)" | mailx -s "Possible Website Issue with ${url}" "$MAIL_LIST"

# Uncomment below to log to syslog
#/bin/logger -p user.err -t WEB-ALERT "Website issue: <a href=\"${url}\">${url}</a> cannot be accessed after ${sleeptime} seconds, with a $timeout second timeout.
fi
fi
done
bash-3.00# ./url_check.ksh
./url_check.ksh[27]: syntax error at line 29 : `else' unmatched
bash-3.00#
# 14  
Old 10-03-2006
'man ksh' yields the following for the 'if' construct:
Code:
     if list ; then list ; [ elif list ; then list ; ... ] [ else list ; ] fi
               The  list  following  if   is  executed and, if it
               returns an exit status of 0,  the  list  following
               the  first  then is executed.  Otherwise, the list
               following elif is executed and, if its value is 0,
               the  list  following  the  next  then is executed.
               Failing that, the else list  is  executed.  If  no
               else  list  or  then list is executed, then the if
               command returns 0 exit status.

'vBcodes' can be found here

Last edited by vgersh99; 10-03-2006 at 04:14 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to check process status

Hi Team, I am using redhat 6.4 version server.We have a script which is used to check the process and sends email if the process is not running.If it is running it will continue and do some other operation. I didnot understand below option -z in the if condition.I have tried to... (5 Replies)
Discussion started by: muraliinfy04
5 Replies

2. Shell Programming and Scripting

UNIX script to check multiple jobs runninng status

Hi Folks, Please help me ,I need a unix shell script to check for multiple jobs running. if there are multiple backup Jobs running then it should be trigger an email . Thanks, Anand T (1 Reply)
Discussion started by: nandu67
1 Replies

3. Linux

Check up the status of a Script (running or not)

Hello, i allready search on google und here in the local Forum, but can't found something. I need a query in php, that check whether a process (script) is running or not. Like this: php query: /usr/bin/Script01 >> if runnig, then: "Script01 is Online", if not "Script01 is Offline" I... (2 Replies)
Discussion started by: ProTechEx
2 Replies

4. Shell Programming and Scripting

How to check the status of script for every 5 min?

Hi, Can any1 provide the code for my req: I am loading few set of files into database through one unix script. I ll try to describe the process: load_cdr-->main script Source Feeds are A & B. File in A-akm.dat File in B-bkm.dat Now my script runs through cron jobs everyday...and for both... (6 Replies)
Discussion started by: gnnsprapa
6 Replies

5. Shell Programming and Scripting

Help....script check status if see something then send email

autorep -m bogus Machine Name Max Load Current Load Factor O/S Status ___________ ________ ___________ ______ ________ ______ bogus --- --- 1.00 Sys Agent Online Status ______ Online Offline Missing Unqualified The "Status" always "Online". I like create a script execute run... (6 Replies)
Discussion started by: dotran
6 Replies

6. Shell Programming and Scripting

Automation, Copy, File Status Check --> Script(s)

All, I have to write a script to do the following requirement. There is a file called BUSINESS_DATE.TXT. This file get updated once the oracle partition created. In Oracle, Partition will be created every day. There is a seperate script scheduled to take care ORACLE partition creation. The... (3 Replies)
Discussion started by: karthi_mrkg
3 Replies

7. Shell Programming and Scripting

PID status

Given a PID ( suppose 1356) . How do i tell if its running or not It would be really helpful if you could explain me .. I got this answer from google but i am unable to understand it ********************************************** Use kill() with 0 for the signal number. There are... (4 Replies)
Discussion started by: ultimatix
4 Replies

8. Shell Programming and Scripting

Check process running Status with PID

Good day I am fairly new to Shell Scripting. I want a script to check if a process is up by checking the process's PID and then return a value for when it's running which would be 0. If it isn't running it should give any other value that 0. Any Help is appreciated Regards (9 Replies)
Discussion started by: 1nsyz1on
9 Replies

9. Shell Programming and Scripting

check exit status - Expect Script

from my main script, i am calling an expect script. there are a lot of conditions in the Expect script and it can have any exit value based on success or failure of the Expect Script. how can i check the exit status of Expect scritp in the main script. (1 Reply)
Discussion started by: iamcool
1 Replies

10. UNIX for Dummies Questions & Answers

how to check exit status in awk script

Hi, I have a main program which have below lines - awk -f test.awk inputFileName - I wonder how to check status return from awk script. content of awk script: test.awk --- if ( pass validation ) { exit 1 } else { (1 Reply)
Discussion started by: epall
1 Replies
Login or Register to Ask a Question