You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.8 KiB
66 lines
1.8 KiB
#!/bin/bash
|
|
|
|
# Author: Nils Gerstner
|
|
# Last revision: 26st Januray 2019
|
|
# Version: v1.5
|
|
# Description: ssh into server from array
|
|
|
|
blue="\e[38;5;25m"
|
|
lightblue="\e[38;5;81m"
|
|
green="\033[0;32m"
|
|
red="\e[38;5;09m"
|
|
yellow="\e[38;5;11m"
|
|
grey="\e[38;5;247m"
|
|
orange="\e[38;5;208m"
|
|
nc="\033[0m"
|
|
bold="\033[1m"
|
|
|
|
sshserver+=("exampleuser@example.com")
|
|
sshcomment+=("Example server")
|
|
sshcolor+=("$red")
|
|
|
|
|
|
sshserver+=("exampleuser@example2.com")
|
|
sshcomment+=("Second examople server")
|
|
sshcolor+=("$orange")
|
|
|
|
sshserver+=("exampleuser@example3.com")
|
|
sshcomment+=("Third example server")
|
|
sshcolor+=("$yellow")
|
|
|
|
sshserver+=("exampleuser@example4.com")
|
|
sshcomment+=("Fourth example server")
|
|
sshcolor+=("$green")
|
|
|
|
pad=" ................................................."
|
|
#pad=" -------------------------------------------------"
|
|
if [ -z "${1}" ]; then
|
|
printf "$grey\e[7m%s$nc\n" "S E R V E R L I S T :"
|
|
for key in "${!sshserver[@]}"; do
|
|
printf "$grey%2d) " "$(( ${key}+1 ))"
|
|
printf "${sshcolor[$key]}%s$grey%s${sshcolor[$key]}%s\n$nc" "${sshserver[$key]}" "${pad:0:$((75-${#sshserver[$key]}-${#sshcomment[$key]}))}" " ${sshcomment[$key]}"
|
|
done
|
|
fi
|
|
|
|
re='^[0-9]+$'
|
|
|
|
if [ -z $1 ]; then
|
|
echo "Please choose a server to connect to"
|
|
read pc
|
|
#echo
|
|
else
|
|
pc="${1}"
|
|
fi
|
|
[[ $pc -eq $pc ]] && echo true || echo false
|
|
while [[ $pc -ne $pc && $pc -gt $(($key+1)) && $ps -lt 0 ]]; do
|
|
>&2 echo "error: '${pc}' is not a number between 1 and $(($key+1))";
|
|
echo "Please choose a server to connect to"
|
|
read pc
|
|
done
|
|
|
|
# Login to server. If login fails, ssh-copy-id to server and try again.
|
|
printf "${sshcolor[$(( pc-1 ))]}%s$bold%s\n$nc" "Connecting to " "${sshserver[$(( $pc-1 ))]}"
|
|
ssh -o PasswordAuthentication=no -o ConnectTimeout=7 ${sshserver[$(( $pc-1 ))]}
|
|
unset sshserver; unset sshcomment & printf "$nc"
|
|
printf "$nc"
|