#!/bin/sh echo "checking if vsftp is alive" status=`/etc/init.d/vsftpd status | /bin/awk ' NR==1 {status = $3}END { print status}'` if [ "$status" = stopped ] then echo "vsftp is stopped! Trying to start again" echo "checking if process is hanging" pid=`ps -ef |grep root.*vsftp | grep -v grep | /bin/awk 'NR==1 {pid=$2} END {print pid}'` echo "pid of hanged process is: " $pid if [ ! "$pid" ] then echo "process is not hanging. Normal restart" /usr/bin/nohup /etc/init.d/vsftpd start else echo "process is hanging. Kill it first" kill -9 $pid /usr/bin/nohup /etc/init.d/vsftpd start fi else echo "vsftp is running. Nothing to do." fi