i an sure i made some typos and this uses "service" not sure every distro has a "service" command
also assumes the vsftpd sctipt can take "status" as an arg
i'm not even sure the process is called "vsftpd" cause i don't use it
but anyway with some debugging and cleaning up/fixing this should work
chmod 755 and make it a start at boot thing i think
Code:
#automated vsftpd check script. Will restart Vsftpd when it's down
#script runs every 30 seconds, checks for pid and pid file, then if not found
#restarts vsftpd
#!/bin/bash
DATE=`date "+%m%d%y [%k:%M]"`
LOGDATE=`date "+%m-%d-%y [%k:%M:%S]"`
mail=/bin/mail
sysadmin=you@yourdomain.com
vsftpfile=/tmp/vsftpd.txt
logfile=/var/log/vsftpdcheck.log
echo "$LOGDATE - Vsftpd Check Service starting up " >> $logfile
function stopvsftpd
{
/sbin/service vsftpd stop
}
function startvsftpd
{
DATE=`date "+%m%d%y [%k:%M]"`
LOGDATE=`date "+%m-%d-%y [%k:%M:%S]"`
stopvsftpd
echo "Vsftpd Service Down, attempting to restart on $DATE" >> $vsftpdfile
cat $vsftpdfile | $mail -s 'Vsftpd Restart' $sysadmin
/sbin/service vsftpd stop
/sbin/service vsftpd start
rm $vsftpdfile
}
function checkpid
{
DATE=`date "+%m%d%y [%k:%M]"`
LOGDATE=`date "+%m-%d-%y [%k:%M:%S]"`
# ps xua | grep -q vsftpd
/sbin/service vsftpd status |grep "is running..."
if [ $? != 0 ]
then
echo "$LOGDATE - No Vsftpd Running" >> $logfile
startvsftpd
else
echo "$LOGDATE - Normal Vsftpd Running" >> $logfile
fi
}
function quit {
function quit {
exit
}
COUNTER=0
while [ $COUNTER -lt 10 ]; do
checkpid
sleep 30s
done