-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_redis_hosts.sh
29 lines (29 loc) · 4.79 KB
/
check_redis_hosts.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
#!/bin/bash │
│
# Specify the Redis command to execute │
REDIS_CMD="CLIENT LIST" │
│
# Specify the path to the file containing the Redis hostnames │
REDIS_HOSTS_FILE="redis_hosts.txt" │
│
if [ $# -ne 1 ]; then │
echo "Usage: ./check_redis_hosts.sh [HOSTS_FILE]" │
exit $E_WRONGARGS │
fi │
│
if [ -f "$1" ]; then │
REDIS_HOSTS_FILE=$1 │
else │
echo "check_redis_hosts.sh: cannot stat '$1': No such file or directory" │
exit $E_NOFILE │
fi │
│
# Loop through each Redis hostname in the file │
while read -r REDIS_HOST; │
do │
# Connect to the Redis host and execute the command │
echo $REDIS_HOST │
redis-cli -h $REDIS_HOST $REDIS_CMD | awk '{ print $2 }' | sed 's/.....//' | sed 's/......$//' | sort | uniq -c; │
done < "$REDIS_HOSTS_FILE" │
│
exit 0