Created
February 21, 2021 07:59
-
-
Save nguyensinhtu/1d134a06a8a90ec7fbeedf1ddcc8d1ab to your computer and use it in GitHub Desktop.
Revisions
-
nguyensinhtu created this gist
Feb 21, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ # find ssh host by name # your ssh's config will be # Host your_host # Hostname your_ip # User your_username _find_host() { local your_host=$1 host="$( awk -v your_host=$your_host ' $1 == "Host" { host = $2 next; } $1 == "Hostname" { host_name = $2; next; } $1 == "User" { $1 = ""; sub( /^[[:space:]]*/, "" ); if (host == your_host) printf "%s@%s \n", $0, host_name; } ' ~/.ssh/config )" echo $host } _find_host your_host