shell script で実現できる。sshに限らず他のコマンドでも可能。
下記の script を chkconfig で登録した script の start などから
(ssh以外のコマンドの場合確認する exit code を修正する必要があるかもしれない)
#!/bin/sh alive=true function term(){ echo echo singal trapped. alive=false for id in ${children[@]}; do kill $id; echo child $id killed done } trap 'term' 2 3 15 while true ; do ssh -N -L 10080:REMOTE_SERVER:80 -i ~/.ssh/key USER@TUNNELL_SERVER & children[$!]=$! wait $! estatus=$? echo child terminated with exit status $estatus unset children[$!] if test $estatus -eq 137 ;then # killed by 9 echo exit the loop break # 子プロセスとして起動した場合は 2,3 では終わらない (上の空行必要) # elif test $estatus -eq 255 ;then # killed by 2, 3 # echo exit the loop # break fi if [ "$alive" != "true" ] ;then break fi echo rerun ssh done echo $(basename $0) end