-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathListSSHServers
More file actions
executable file
·40 lines (32 loc) · 1.28 KB
/
ListSSHServers
File metadata and controls
executable file
·40 lines (32 loc) · 1.28 KB
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
#!/bin/bash
# === Settings ===
CONFIG_DIR="$HOME/.ssh/config.d"
if [[ ! -d "$CONFIG_DIR" ]]; then
echo "❌ No config.d directory found at $CONFIG_DIR"
exit 1
fi
echo "=============================================================="
echo " 🖥️ Saved SSH Servers"
echo "=============================================================="
printf "%-20s %-20s %-15s\n" "Server Name" "IP Address" "User"
echo "---------------------------------------------------------------"
for file in "$CONFIG_DIR"/*.conf; do
if [[ -f "$file" ]]; then
# Initialize empty values
SERVER_NAME=""
IP_ADDRESS=""
SSH_USER=""
while IFS= read -r line; do
# Trim leading whitespace for pattern matching
trimmed_line=$(echo "$line" | sed 's/^[[:space:]]*//')
if [[ "$trimmed_line" =~ ^Host[[:space:]]+(.+) ]]; then
SERVER_NAME="${BASH_REMATCH[1]}"
elif [[ "$trimmed_line" =~ ^HostName[[:space:]]+(.+) ]]; then
IP_ADDRESS="${BASH_REMATCH[1]}"
elif [[ "$trimmed_line" =~ ^User[[:space:]]+(.+) ]]; then
SSH_USER="${BASH_REMATCH[1]}"
fi
done < "$file"
printf "%-20s %-20s %-15s\n" "$SERVER_NAME" "$IP_ADDRESS" "$SSH_USER"
fi
done