-
Notifications
You must be signed in to change notification settings - Fork 0
/
msh.sh
33 lines (33 loc) · 1.07 KB
/
msh.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
#########################################
## * * * * * * * * * * * * * * * * * * ##
## * Bash Minicom Style SSH Manager * ##
## * Mikhail Barinov dev@mbarinov.ru * ##
## * Version 1.0.1 05.05.2022 * ##
## * * * * * * * * * * * * * * * * * * ##
#########################################
clear
selectssh(){
hosts_arr=( $(cat ~/.ssh/config | grep -P "Host\s[a-zA-Z0-9]{1,}" | cut -d " " -f 2) );
bold=$(tput bold);
normal=$(tput sgr0);
arraylength=${#hosts_arr[@]};
echo -e "\v${bold}Please select which Host to use SSH with:\v";
echo "Existing SSH [pre]sets:${normal}";
for (( i=1; i<=${arraylength}; i++ ));
do
echo -e "[$i]:\t${hosts_arr[$i-1]}";
done
echo -e "\v"
read -e -p "Please select a valid host number (from 1 to ${arraylength})> " NUM
hnum=( $(echo $NUM | egrep -oh "[0-9]{1,}") );
if [[ $hnum -gt 0 ]] && [[ $hnum -le ${arraylength} ]];
then
clear;
echo -e "${bold}Host:\t${hosts_arr[$hnum-1]}${normal}";
ssh ${hosts_arr[$hnum -1]};
else
selectssh;
fi
}
selectssh;