The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Check FTP Status april Shell Programming and Scripting 2 05-06-2009 09:04 AM
check exit status - Expect Script iamcool Shell Programming and Scripting 1 01-02-2008 09:07 AM
how to check exit status in awk script epall UNIX for Dummies Questions & Answers 1 06-24-2006 08:27 PM
check the status and send an email with status isingh786 Shell Programming and Scripting 3 12-29-2005 07:22 PM
Ftp Status Check acheepi Shell Programming and Scripting 4 09-08-2005 04:23 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-03-2006
zeekblack zeekblack is offline
Registered User
  
 

Join Date: Sep 2002
Posts: 16
Question Script to check status of a PID

i'm just learning scripting, and have been banging my head against this

I want to check if my WAS6 java process is running and if so..echo me a messages. If not then echo me a different messages

the problem i have is I dont know how to represent a NULL return value. If i grep for a was6 java pid, the $? is always '0'...no matter if a PID came back or not. any idea on how to write/rewrite this??

PID=`/usr/ucb/ps -auxwww |grep -i [s]erver1 |grep -v grep | awk '{print $2}'`

if [ $? -eq ] ; then ( i have also tried `if [ $PID -eq ] ; then)
echo " WAS6 is down,please restart"
else
echo " WAS6 is running, no action needed"
fi
--------------------------------------------------------------------

In addition, i've tried this variation below, which seems like works ..but i always get the error when executing..

# cat test.ksh
#!/bin/ksh
#
# Check to see if URLs respond in a given time period
#
BASE_DIR="/local/apps/adminutils"
WGET="$BASE_DIR/bin/wget"
DAT_FILE="$BASE_DIR/etc/url_check.dat"
MAIL_LIST="user@net.net"

PID=`/usr/ucb/ps -auxwww |grep -i [s]erver1 |grep -v grep | awk '{print $2}'`
if [ $PID = ] ; then
echo " WAS6 is down,please restart"
else
echo " WAS6 is running, no action needed"
fi
# ./test.ksh
./test.ksh[11]: test: argument expected
WAS6 is running, no action needed
#

~
  #2 (permalink)  
Old 10-03-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
if [ -z "$PID" ] ; then 
echo " WAS6 is down,please restart"
else
echo " WAS6 is running, no action needed"
fi
z option is used to check whether variable is null
  #3 (permalink)  
Old 10-03-2006
zeekblack zeekblack is offline
Registered User
  
 

Join Date: Sep 2002
Posts: 16
Talking

thank you so very much... I HAVE search countless books and searched the entire library on www.books24x7.com and safair.orielly.com and none of then could tell me this...

i'll be a regular on this forum for sure...tks again...i'll try this method out
  #4 (permalink)  
Old 10-03-2006
zeekblack zeekblack is offline
Registered User
  
 

Join Date: Sep 2002
Posts: 16
btw, do any of you guys know where I can get a list of these kind of directives and what they do?

Im trying to get better at shell scripting....but its like trying to write a letter without knowing the dictionary....

-z
-eq
-$?

etc..etc...etc...
  #5 (permalink)  
Old 10-03-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,426
You can read the following document :KornShell 88 Manual Page
You will find ather links on the page KornShell Documentation

Jean-Pierre.
  #6 (permalink)  
Old 10-03-2006
zeekblack zeekblack is offline
Registered User
  
 

Join Date: Sep 2002
Posts: 16
thank you,will read!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:10 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0