sshin/sshin

30 lines
921 B
Bash
Executable File

#!/bin/bash
usage() {
echo "Usage: sshin user hostname/last byte of IP address"
echo
echo "This tools automatically chooses the server port based on the port_association file in ~/local/share/sshin/port_association"
echo
echo "Example: \"sshin foo bar.com \" will run \"ssh foo@bar.com -p 2323\""
echo "Example: \"sshin foo 43 \" will run \"ssh foo@192.168.1.43\""
return
}
IP_PREFIX="192.168.1."
[[ $# -le 1 ]] && usage && exit 1
[[ $1 = "-h" ]] && usage -h && exit 1
re='^[0-9]+$'
command="ssh ${1}@"
shift
#[[ $1 =~ $re ]] && command="${command}192.168.1.$2" || port=$(grep $1 ~/.local/share/sshin/port_association | awk '{print $NF}') && command="${command}$1 -p $port"
if [[ $1 =~ $re ]]
then
command="${command}192.168.1.$1"
else
port=$(grep $1 ~/.local/share/sshin/port_association | awk '{print $NF}')
command="${command}$1"
[[ -n $port ]] && command="${command} -p $port"
fi
echo $command
$command