#!/bin/bash declare SSHD_PID="/var/run/sshd.pid" declare SSHD_SERVICE="/etc/rc.d/rc.sshd" # for debugging... # SSHD_SERVICE="echo" declare SSHD_RESTART="${SSHD_SERVICE} restart" declare SSHD_STOP="${SSHD_SERVICE} stop" declare SSHD_START="${SSHD_SERVICE} start" declare CHECK_INTERVAL=15 sshd_check() { if [ -r ${SSHD_PID} ]; then if ps h -p `cat ${SSHD_PID}` &> /dev/null ; then return else ${SSHD_RESTART} # restart needs sshd.pid to exist fi else ${SSHD_STOP} # for paranoia in case a listening socket's hung ${SSHD_START} fi date +"%c %z: [sshd] Needed to restart." } while true; do sshd_check sleep ${CHECK_INTERVAL} done