-
Notifications
You must be signed in to change notification settings - Fork 0
/
myssh.sh
executable file
·67 lines (59 loc) · 1.51 KB
/
myssh.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
58
59
60
61
62
63
64
65
66
67
#!/bin/bash -e
# SSH Script
# Create By Donni Triosa (donni.triosa94@gmail.com)
#validate params
if [[ $# -lt 1 ]]
then
echo "++===============================++"
echo "|| Parameter Required ||"
echo "++===============================++"
exit 1
fi
main=$1
# Directory containing the files
directory="/Volumes/Data_Drive_HD/Code/Shell/ssh-script"
found=false
# Loop through all files in the directory
for file in "$directory"/*
do
# Check if it's a file
if [[ -f $file ]]
then
# Print the file name without the path
filename=$(basename "$file")
# Check if the parameter matches the file name
if [[ $main == ${filename%.*} ]]
then
found=true
break
fi
fi
done
# if found, execute the script
clear
if [[ $found == true ]]
then
awk '/^$/ {exit} 1' /Volumes/Data_Drive_HD/Code/Shell/ssh-script/${main}.txt
line=$(awk '/^$/ {exit} {print NR}' /Volumes/Data_Drive_HD/Code/Shell/ssh-script/${main}.txt | tail -n 1)
let menu=$line-2
read -p "Enter your choice: " server
if [[ $server -gt 0 && $server -lt $menu ]]
then
let server=$server+1+$line
# Get the command from the specific line
command=$(sed -n "${server}p" /Volumes/Data_Drive_HD/Code/Shell/ssh-script/${main}.txt)
# Execute the command
clear
echo $command
eval "ssh $command"
else
echo "Invalid input!"
exit 1
fi
else
echo "++===============================++"
echo "|| CSP NOT FOUND ||"
echo "++===============================++"
exit 1
fi
exit 0