MacOS’ta ssh tünel açan script

Daha önce ssh tünel olup olmadığına bakmak gerekiyor.


#!/bin/bash
echo "Looking if tunnel is running in the background."
pid=$(ps -ef | grep "4999:10.0.0.99:4999" | grep -v grep | cut -d" " -f6)
if [[ -n $pid ]]; then
echo "Previous ssh tunnel detected."
echo "Killing ssh process: "+$pid
kill $pid
fi
echo "Creating ssh tunnel."
ssh -L 4999:10.0.0.99:4999 -fNC root@myserver.com
echo "Successfully created ssh tunnel."

Yorum bırakın