-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysql.sh
More file actions
29 lines (24 loc) · 744 Bytes
/
mysql.sh
File metadata and controls
29 lines (24 loc) · 744 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
#!/bin/bash
# ${arr[@]} # All of the items in the array
# ${!arr[@]} # All of the indexes in the array
# ${#arr[@]} # Number of items in the array
# ${#arr[0]} # Length of item zero
# CSV:
query="select concat_ws(',', quote(concat('\"\'%> ', Host, ' <*.)')), quote(char_length(Host))) from user"
# -- OR --
# INTO OUTFILE '/tmp/hosts.csv'
# FIELDS TERMINATED BY ','
# ENCLOSED BY '"'
# LINES TERMINATED BY '\n';
dbname="mysql"
array=()
while read line; do
array+=("$line")
done < <(mysql -uroot -S /tmp/mysql.sock ${dbname} -sNoBe "${query}")
for index in ${!array[*]}
do
printf "%4d: %s\n" $index "${array[$index]}"
done
function joined { printf "1=1";printf "%s" "${@/#/ AND }"; }
echo ${#array[@]} elements
joined "${array[@]}"