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
#
~
|