sshin/sshin

30 lines
921 B
Plaintext
Raw Normal View History

2021-10-28 16:02:13 +02:00
#!/bin/bash
usage() {
2021-10-28 16:15:00 +02:00
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\""
2021-10-28 16:17:57 +02:00
echo "Example: \"sshin foo 43 \" will run \"ssh foo@192.168.1.43\""
2021-10-28 16:02:13 +02:00
return
}
IP_PREFIX="192.168.1."
[[ $# -le 1 ]] && usage && exit 1
[[ $1 = "-h" ]] && usage -h && exit 1
re='^[0-9]+$'
command="ssh ${1}@"
shift
2021-10-28 16:15:00 +02:00
#[[ $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"
2021-10-28 16:15:00 +02:00
fi
echo $command
2021-10-28 16:15:00 +02:00
$command