-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsshko.sh
executable file
·57 lines (48 loc) · 1.17 KB
/
sshko.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
logFile=~/.sshLog.txt
#logFile=./file.txt
if [[ ! -e ${logFile} ]]; then
touch ${logFile}
fi
if [ "$1" == "" ] || [ $# -gt 1 ]; then
if ! [ -s ${logFile} ]; then
echo "ssh log file is empty"
exit
fi
HEIGHT=20
WIDTH=40
CHOICE_HEIGHT=9
BACKTITLE="This is made, because you are super lazy!!!!"
TITLE="SSHko"
MENU="Choose one of the following ssh connections:"
arr=()
val=()
key=0
while IFS= read -r line || [[ "$line" ]]; do
arr+=($key "$line")
val+=("$line")
((key = key + 1))
done <${logFile}
for key in "${!arr[@]}"; do
echo ${arr[$key]}
done
echo ${#arr[@]}
CHOICE=$(dialog --clear --title "$TITLE" --backtitle "$BACKTITLE"\
--menu "$MENU" $HEIGHT $WIDTH $CHOICE_HEIGHT "${arr[@]}" \
2>&1 >/dev/tty)
clear
if [[ ! $CHOICE == "" ]]; then
sshHost=${val[$CHOICE]}
echo "$CHOICE You chose ${sshHost}"
ssh ${sshHost}
exit
fi
else
sshHost=$1
# echo ${sshHost} >> ${logFile}
if ! grep -Fxq "$sshHost" ${logFile}; then
echo ${sshHost} >>${logFile}
fi
ssh ${sshHost}
exit
fi