forked from ddev/ddev-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
general_log
executable file
·62 lines (52 loc) · 1.59 KB
/
general_log
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
#!/bin/bash
## Description: Enable and show database general_log. Disables log after exiting (via CTRL+C)
## Usage: general_log
# saner programming env: these switches turn some bugs into errors
set -o errexit -o pipefail -o noclobber -o nounset
endC="\033[0m"
greenb="\033[1;32m"
purpleb="\033[1;35m"
#red="\033[0;31m"
noticeC=$purpleb
successC=$greenb
#errorC=$red
function spinner() {
function cursorBack() {
echo -en "\033[$1D"
}
# make sure we use non-unicode character type locale
# (that way it works for any locale as long as the font supports the characters)
local LC_CTYPE=C
local pid=$1 # Process Id of the previous running command
spin="-\|/"
local iSpinner=0
local charwidth=1
tput civis # cursor invisible
while kill -0 "$pid" 2>/dev/null; do
iSpinner=$(((iSpinner + charwidth) % ${#spin}))
printf "$noticeC%s$endC" "${spin:$iSpinner:$charwidth}"
cursorBack 1
sleep .1
done
tput cnorm
wait "$pid" # capture exit code
return $?
}
function enable() {
printf "Enabling general_log "
mysql -uroot -proot <<< "SET GLOBAL general_log_file='general_log.log'"
mysql -uroot -proot <<< "SET GLOBAL general_log=1" &
spinner $!
printf "%b✓%b \n" "${successC}" "${endC}"
printf "%bPress CTRL+C to exit.%b\n\n" "${noticeC}" "${endC}"
}
function shutdown() {
printf " \n\nDisabling general_log "
mysql -uroot -proot <<< "SET GLOBAL general_log=0" &
spinner $!
printf "%b✓%b \n" "${successC}" "${endC}"
exit 0
}
trap shutdown INT
enable
tail -f /var/lib/mysql/general_log.log