Running a do:while loop to montior for a process in memory and within
that loop, I do a condition check for a process...if it comes back
missing, if PROC = "" then echo to log file that it's down and execute
a restart.
For my restart, I've tried to actually start it as root with su -c
"/home/user/run.sh" and I've tried to embed the su -c command execution
within a script and call that script.
Problem is, when I kill the process to be monitored, it is able to see
that it's down and it will run the startMileage script, but it never
restarts my process and I just see sh /root/old/startMileage stuck
running when I do a ps for it. So, it starts, but it never finishes??
Anyway, if I run the startMileage script manually, it works fine.
What is best way to execute a script/command from within that if:then
loop?
##############################################################################
LOGDIR="/usr/local/logs"
LOGFILE="$LOGDIR/CheckMileage.log"
MILE_DOWN="The Mileage process is not active on `hostname` : `date`"
echo "`date` : CheckMileage started..." >> $LOGFILE
while :
do
sleep 120
echo "******************************************" >>
$LOGFILE
echo "\t\t`date`" >>
$LOGFILE
echo "\nMileage status--" >>
$LOGFILE
ps -ef | grep "MileageCalculator" | grep -v grep >>
$LOGFILE
MILEAPP=`ps -ef | grep "MileageCalculator" | grep -v grep`
if [ "$MILEAPP" = "" ]
then
echo $MILE_DOWN >>
$LOGFILE
echo `date` >>
$LOGFILE
echo "Restarting Mileage and Notifying System
Administration....." >> $LOGFILE
echo "Sleeping 10 before attempt to restart
MileageCalculator" >> $LOGFILE
echo "Running: /root/old/startMileage" >> $LOGFILE
sh /root/old/startMileage
fi
done
return 1
that loop, I do a condition check for a process...if it comes back
missing, if PROC = "" then echo to log file that it's down and execute
a restart.
For my restart, I've tried to actually start it as root with su -c
"/home/user/run.sh" and I've tried to embed the su -c command execution
within a script and call that script.
Problem is, when I kill the process to be monitored, it is able to see
that it's down and it will run the startMileage script, but it never
restarts my process and I just see sh /root/old/startMileage stuck
running when I do a ps for it. So, it starts, but it never finishes??
Anyway, if I run the startMileage script manually, it works fine.
What is best way to execute a script/command from within that if:then
loop?
##############################################################################
LOGDIR="/usr/local/logs"
LOGFILE="$LOGDIR/CheckMileage.log"
MILE_DOWN="The Mileage process is not active on `hostname` : `date`"
echo "`date` : CheckMileage started..." >> $LOGFILE
while :
do
sleep 120
echo "******************************************" >>
$LOGFILE
echo "\t\t`date`" >>
$LOGFILE
echo "\nMileage status--" >>
$LOGFILE
ps -ef | grep "MileageCalculator" | grep -v grep >>
$LOGFILE
MILEAPP=`ps -ef | grep "MileageCalculator" | grep -v grep`
if [ "$MILEAPP" = "" ]
then
echo $MILE_DOWN >>
$LOGFILE
echo `date` >>
$LOGFILE
echo "Restarting Mileage and Notifying System
Administration....." >> $LOGFILE
echo "Sleeping 10 before attempt to restart
MileageCalculator" >> $LOGFILE
echo "Running: /root/old/startMileage" >> $LOGFILE
sh /root/old/startMileage
fi
done
return 1