File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # Define colors
4+ RESET=" \033[0m"
5+ CYAN=" \033[36m"
6+ YELLOW=" \033[33m"
7+ GREEN=" \033[32m"
8+ MAGENTA=" \033[35m"
9+ RED=" \033[31m"
10+
11+ # MySQL credentials
12+ MYSQL_USER=" root" # Replace with your MySQL username
13+ MYSQL_PASS=" devops" # Replace with your MySQL password
14+ MYSQL_HOST=" localhost" # Change if not running MySQL locally
15+
16+ # Run MySQL SHOW PROCESSLIST command
17+ RESULT=$( mysql -u$MYSQL_USER -p$MYSQL_PASS -h$MYSQL_HOST -e " SHOW PROCESSLIST;" 2> /dev/null)
18+
19+ # Check for errors
20+ if [[ $? -ne 0 ]]; then
21+ echo -e " ${RED} Error connecting to MySQL. Check your credentials.${RESET} "
22+ exit 1
23+ fi
24+
25+ # Process and colorize output
26+ echo -e " ${CYAN} --- SHOW PROCESSLIST Result ---${RESET} "
27+ echo " $RESULT " | while IFS= read -r line; do
28+ if [[ $line == * " Id" * && $line == * " Command" * ]]; then
29+ # Header
30+ echo -e " ${YELLOW}${line}${RESET} "
31+ else
32+ # Data rows
33+ echo " $line " | awk -v reset=" $RESET " -v green=" $GREEN " -v cyan=" $CYAN " -v magenta=" $MAGENTA " -v yellow=" $YELLOW " '
34+ {
35+ printf cyan $1 reset "\t" green $2 reset "\t" magenta $3 reset "\t" yellow $4 reset "\t";
36+ for (i = 5; i <= NF; i++) printf $i " ";
37+ printf "\n";
38+ }'
39+ fi
40+ done
You can’t perform that action at this time.
0 commit comments