diff options
author | InigoGutierrez <inigogf.95@gmail.com> | 2019-05-21 05:26:34 +0200 |
---|---|---|
committer | InigoGutierrez <inigogf.95@gmail.com> | 2019-05-21 05:26:34 +0200 |
commit | ff5b407fb4337aaea80da92cce9a526c52ccff10 (patch) | |
tree | 12b43c7e4f5550891935a7e11858fd523426ba87 /ssh.sh | |
parent | 1c080783990429918a4b7fa4d383b36bf63fae1f (diff) | |
download | scripts-ff5b407fb4337aaea80da92cce9a526c52ccff10.tar.gz scripts-ff5b407fb4337aaea80da92cce9a526c52ccff10.zip |
Created scripts for using ssh and scp with common hosts.
Diffstat (limited to 'ssh.sh')
-rwxr-xr-x | ssh.sh | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -0,0 +1,16 @@ +#!/bin/sh +# Allows to select a host to connect to through ssh +# Hosts are read from the file $hostsfile, in which each line should be a host in the form identifier#address#port#input for pass +# Port and input for pass are optional + +hostsfile="$HOME/.hosts" +hostnames="$(cut -d'#' -f1 < "$hostsfile" | fzf)" +host="$(grep "$hostnames" < "$hostsfile")" +hostname="$(echo "$host" | cut -d'#' -f1)" +hostaddress="$(echo "$host" | cut -d'#' -f2)" +hostport="$(echo "$host" | cut -d'#' -f3)" +hostpass="$(echo "$host" | cut -d'#' -f4)" +echo "Connecting to $hostname" +[ "$hostpass" ] && pass -c "$hostpass" +[ "$hostport" ] && ssh $hostaddress -p $hostport || ssh $hostaddress # No quotes here! +#$(echo "ssh $hostaddress -p $hostport") # Alternative to prev line |