Skip to content

Instantly share code, notes, and snippets.

@tst2005
Created March 10, 2017 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tst2005/4fffa5c785f65edf1e919a19b453c60a to your computer and use it in GitHub Desktop.
Save tst2005/4fffa5c785f65edf1e919a19b453c60a to your computer and use it in GitHub Desktop.
wrapper for ssh and scp to connect to temporary servers
#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