-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql_process_list.sh
More file actions
executable file
·54 lines (41 loc) · 1.02 KB
/
sql_process_list.sh
File metadata and controls
executable file
·54 lines (41 loc) · 1.02 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
#@lroehrs / Profihost AG 2021
#-CONFIG-#
#required
user="user"
pw="password"
#optional
db=""
host=""
port="3307"
log_file="" #if set, adapt find
log_path=""
#-SCRIPT-#
set -e
xdate="$(date "+%d_%m_%Y")"
xtime="$(date "+TIME: %H:%M:%S")"
cd $(dirname "$0")
if [[ -z $db ]]; then
db="usrdb_${user}"
fi
if [[ -z $log_path ]]; then
log_path="/home/$(whoami)/custom_log/"
if [[ ! -d $log_path ]]; then
mkdir "$log_path"
fi
fi
if [[ -z $host ]]; then
host="127.0.0.1"
fi
if [[ -z $port ]]; then
port="3306"
fi
if [[ -z $log_file ]];then
log_file="sql_process_${xdate}.log"
fi
log="${log_path}${log_file}"
xmysql="/usr/local/mysql5/bin/mysql --user=${user} --password=${pw} --host=${host} --port=${port} ${db}"
echo -e "\n $xtime \n\n $($xmysql -e "SELECT ID, USER, DB, COMMAND, TIME, STATE, INFO FROM INFORMATION_SCHEMA.PROCESSLIST ORDER BY TIME DESC") \n---------------------------------------------------" >> $log
for a in $(find $log_path -mtime +30 -name "sql_process_*" -print); do
rm -v $a
done