Created
March 10, 2017 12:48
-
-
Save tst2005/4fffa5c785f65edf1e919a19b453c60a to your computer and use it in GitHub Desktop.
wrapper for ssh and scp to connect to temporary servers
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
#alias sshtmp='ssh -oUserKnownHostsFile="$HOME/.ssh/tmp_known_hosts"' | |
#alias scptmp='scp -oUserKnownHostsFile="$HOME/.ssh/tmp_known_hosts"' | |
alias sshtmpreset='>$HOME/.ssh/tmp_known_hosts ;#' | |
alias sshtmp='__sshtmp_cmd ssh' | |
alias scptmp='__sshtmp_cmd scp' | |
__sshtmp_cmd() { | |
local cmd="$1";shift | |
local host="$1" | |
local user='' | |
case "$1" in | |
(-*) echo >&2 "first argument must be [user@]host"; return 1 ;; | |
(*?@?*) | |
user="${1%%@*}" | |
host="${1#*@}" | |
;; | |
(?*) | |
user='' | |
host="$1" | |
;; | |
esac | |
local newhost="$(grep -- '^[^[:space:]]\+[[:space:]]\+\<'"$1"'\>' "$HOME/.ssh/tmp_hosts" | cut -d\ -f1 | cut -d $'\t' -f1)" | |
newhost="$user${user:+@}${newhost:-$1}" | |
shift | |
"$cmd" -oUserKnownHostsFile="$HOME/.ssh/tmp_known_hosts" "$newhost" "$@" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment