All pastes #1510402 Raw Edit

sshd daemon watcher

public shellscript v1 · immutable
#1510402 ·published 2009-07-28 21:13 UTC
rendered paste body
#!/bin/bashdeclare 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=15sshd_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