Ill try to make this brief:
I am trying to get the script below to run another script defined as BATNAM.
The script runs fine, does what i designed it to do, however...
I would like it to mailx the NEW $pid that was restarted.
This script is supposed to go in crontab as root, and run by the min checking if $pid exists.
Lastly, should i try a diff approach, maybe a "while" or "until"? rather than "if/then/else"
I have tried sleep 10, as it does take more than 7 seconds for the script to show up in ps -ef|grep myusername.
could you pls review the code below, and make suggestions.
This is a simple syntax issue and I am unable to find it.
I am on hpux / /usr/bin/sh, and I have root if necessary.
thanks!
#!/usr/bin/sh -x
# set the locals
stty intr '^c'
# set the vars
BATDIR="/usr/script8/batch" # batch dir
BATNAM="bat_fstsi61c.sh" # batch process file
BATPF="bat_fstsi61.pf" # batch to grep
BATSVC="SIGTEST" # mail topic
BATPF="bat_fstsi61.pf" # batch to grep
SERVER="PHANTOM" # servername here
SDIR="/apps/sigmon/dvl/fst61" # sigmon dir
SIN="$SDIR/in" # in dir
SPROC="$SDIR/proc" # proc dir
SLOG="/usr/script8/batch/LOGS" # log dir
SMAIL="/usr/script8/batch/EMAILS" # email log dir
SMAILER="petey" # person(s) to email
# export the vars
export BATDIR BATNAM BATSVC BATPF SERVER SDIR SIN \
SPROC SLOG SMAIL SMAILER
pid=`ps -ef|grep "$BATPF" |grep -v grep |awk -F" " '{print $2}'`
echo $pid
if [ "$pid" = "" ]
then
/usr/bin/sh $BATDIR/$BATNAM
sleep 10
mailx -s "${SERVER} ${BATNAM} restarted" petey
sleep 10
echo "$pid" > $SLOG/"$BATNAM-restart-on--`date +%F-%T`"
else
echo "service is ok"
pid=""
fi