Skip to content

Instantly share code, notes, and snippets.

@iwinux
Created October 31, 2012 01:49
Show Gist options
  • Save iwinux/3984337 to your computer and use it in GitHub Desktop.
Save iwinux/3984337 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
@vietor
Copy link

vietor commented Oct 31, 2012

加上自动输入登录的脚本会更好些

@iwinux
Copy link
Author

iwinux commented Nov 2, 2012

@vietor 这个只要在 ~/.ssh/config 设置就行了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment