diff options
-rwxr-xr-x | scp.sh | 14 | ||||
-rwxr-xr-x | ssh.sh | 16 |
2 files changed, 30 insertions, 0 deletions
@@ -0,0 +1,14 @@ +#!/bin/sh +# Allows to select a host to send files to through scp + +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)" +targetPath="$(echo "$host" | cut -d'#' -f5)" +echo "Sending to $hostname" +[ "$hostpass" ] && pass -c "$hostpass" +[ "$hostport" ] && scp -P $hostport "$@" $hostaddress:$targetPath || scp "$@" $hostaddress:$targetPath # No quotes here! @@ -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 |