SHOW:
|
|
- or go back to the newest paste.
1 | #!/bin/bash | |
2 | ||
3 | start_daytime=$(date --date "$1 00:00:00" +%s) | |
4 | end_daytime=$(date --date "$2 00:00:00" +%s) | |
5 | itemid=${3:-23347} | |
6 | - | itemid="'"$itemid"'" |
6 | + | |
7 | sql_string="select history.itemid, items.name, history.clock, history.value \ | |
8 | - | sql_string="select * from history where value = \ |
8 | + | from history INNER JOIN items ON history.itemid=items.itemid \ |
9 | - | ( select max(value) from history where itemid=$itemid and \ |
9 | + | where value = ( select max(value) from history where itemid=$itemid and \ |
10 | - | clock >= $start_daytime and clock <= $end_daytime) \ |
10 | + | clock >= $start_daytime and clock <= $end_daytime) \ |
11 | - | and itemid=$itemid and clock >= $start_daytime and clock <= $end_daytime" |
11 | + | and history.itemid=$itemid and history.clock >= $start_daytime \ |
12 | and history.clock <= $end_daytime\G" | |
13 | - | mysql -B -s -u root -p zabbix -e "$sql_string" |
13 | + | |
14 | for f in $(mysql -B -s -r -u root -p zabbix -e "$sql_string" | sed -e '/^\*.*\*$/d' -e 's/ //g') | |
15 | do | |
16 | if [ ${f%:*} = "clock" ]; then | |
17 | date_str=$(date --date @${f##*:}) | |
18 | echo ${f%:*}:${date_str} | |
19 | else | |
20 | echo $f | |
21 | fi | |
22 | done |