#! /bin/bash
# check to see if site is up
# if it is, don't worry
# if it's down, restart apache after get a process listing
#
# v.1 Warren M Myers - initial stab
# 31 Aug 06
#
ERRCOD='7'
WHEN=`date +%d%b%y`
REPT="~/psaux.$WHEN.txt"
STARS='********************'
curl -I http://www.shodor.org > /var/tmp/curlret.txt
if [ "$?" = "$ERRCOD" ]; then
# return was unable to connect to host: save ps -aux; mail report
ps -aux > $REPT
echo $STARS
echo 'curl return results'
echo
cat curlret.txt
echo
echo $STARS
echo 'ps -aux results'
cat $REPT
echo
echo $STARS
echo 'restarting apache'
/etc/init.d/apache2 restart
echo 'apache restarted'
echo
echo "ps -aux results saved in $REPT"
fi
rm -f /var/tmp/curlret.txt