Created
December 29, 2014 09:09
-
-
Save hikerpig/f579b4acdc95df5e5a74 to your computer and use it in GitHub Desktop.
Setup a ssh session that can utilize the remote server's clipboard.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PORT=5566 | |
ssh_server='ubuntu@crmdev' | |
# using mac | |
if [[ -n `which pbcopy` ]]; then | |
echo "@Mac" | |
copy_command='pbcopy' | |
elif [[ -n `which xsel` ]]; then | |
echo "you can use xsel on ubuntu" | |
copy_command='xsel' | |
else | |
echo "you don't have clipboard utility" | |
fi | |
existed=`ps | grep nc | grep $PORT` | |
# start a netcat server | |
if [[ -n $existed ]]; then | |
echo "nc $PORT already existed" | |
else | |
echo "nc $PORT does not exist" | |
if [[ -n $copy_command ]]; then | |
while : ;do nc -l localhost $PORT | $copy_command ; done & | |
fi | |
fi | |
# ssh the server | |
if [[ -n $copy_command ]]; then | |
ssh -R $PORT:localhost:$PORT $ssh_server | |
else | |
ssh $ssh_server | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment