-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetchecker.sh
More file actions
38 lines (30 loc) · 813 Bytes
/
netchecker.sh
File metadata and controls
38 lines (30 loc) · 813 Bytes
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
#!/bin/bash
# netchecker.sh
host="$1"
shift
# Handle datetime (quoted or split in two)
if [ "$#" -eq 1 ]; then
datetime="$1"
elif [ "$#" -eq 2 ]; then
datetime="$1 $2"
else
echo "Usage: $0 <host> <YYYY-MM-DD HH:MM>"
exit 1
fi
# Extract up to and including the 2nd hyphen, e.g., "dbgsc-r-"
pattern=$(echo "$host" | awk -F'-' '{print $1 "-" $2 "-"}')
echo ">>> Extracted pattern: $pattern"
# Get matching hosts
echo ">>> Searching mysql_hosts.txt..."
hosts=$(grep -vE 'rtdb|web' mysql_hosts.txt | grep "$pattern")
if [ -z "$hosts" ]; then
echo "No matching hosts found for pattern $pattern"
exit 1
fi
echo ">>> Hosts found:"
echo "$hosts"
# Run command on each host
for i in $hosts; do
echo ">>> Running on $i"
ssh -q "$i" "echo $i && /root/MySQL/netcheck.sh $datetime"
done