Skip to content

Instantly share code, notes, and snippets.

@holys
Forked from iwinux/monssh.sh
Created November 5, 2012 17:06
Show Gist options
  • Save holys/4018346 to your computer and use it in GitHub Desktop.
Save holys/4018346 to your computer and use it in GitHub Desktop.
monitor SSH status
#! /bin/bash
# usage: monssh [hostname]
if [[ -z $1 ]]
then
HOST="YOURHOST"
else
HOST=$1
fi
CMD="ssh -fqND 9999 $HOST"
while true
do
pgrep -fl "$CMD" > /dev/null 2>&1
if [[ $? -eq 0 ]]
then
echo "[`date`] Status: OK."
else
echo "Status: launching $CMD"
$CMD
fi
sleep 30
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment