Skip to content

Commit dfd6eeb

Browse files
committed
Use loop for SQLs on history/trends
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
1 parent 34d5410 commit dfd6eeb

File tree

2 files changed

+10
-40
lines changed

2 files changed

+10
-40
lines changed

checkscript.sh

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -153,26 +153,11 @@ mysql_w "SELECT COUNT(*) FROM trigger_depends WHERE triggerid_up NOT IN (SELECT
153153

154154

155155
echo "Count the amount of records in the history/trends table for items that no longer exist"
156-
echo -n "Table: history orphaned items: "
157-
mysql_w "SELECT COUNT(itemid) FROM history WHERE itemid NOT IN (SELECT itemid FROM items);"
158-
159-
echo -n "Table: history_uint orphaned items: "
160-
mysql_w "SELECT COUNT(itemid) FROM history_uint WHERE itemid NOT IN (SELECT itemid FROM items);"
161-
162-
echo -n "Table: history_log orphaned items: "
163-
mysql_w "SELECT COUNT(itemid) FROM history_log WHERE itemid NOT IN (SELECT itemid FROM items);"
164-
165-
echo -n "Table: history_str orphaned items: "
166-
mysql_w "SELECT COUNT(itemid) FROM history_str WHERE itemid NOT IN (SELECT itemid FROM items);"
167-
168-
echo -n "Table: history_text orphaned items: "
169-
mysql_w "SELECT COUNT(itemid) FROM history_text WHERE itemid NOT IN (SELECT itemid FROM items);"
170-
171-
echo -n "Table: trends orphaned items: "
172-
mysql_w "SELECT COUNT(itemid) FROM trends WHERE itemid NOT IN (SELECT itemid FROM items);"
173-
174-
echo -n "Table: trends_uint orphaned items: "
175-
mysql_w "SELECT COUNT(itemid) FROM trends_uint WHERE itemid NOT IN (SELECT itemid FROM items);"
156+
TABLES=(history history_uint history_log history_str history_text trends trends_uint)
157+
for table in "${TABLES[@]}"; do
158+
echo -n "Table: $table orphaned items: "
159+
mysql_w "SELECT COUNT(itemid) FROM $table WHERE itemid NOT IN (SELECT itemid FROM items);"
160+
done
176161

177162

178163
echo "Count the amount of records in the events table for triggers/items that no longer exist"

cleanup.sh

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -153,26 +153,11 @@ mysql_w "DELETE FROM trigger_depends WHERE triggerid_up NOT IN (SELECT triggerid
153153

154154

155155
echo "Delete records in the history/trends table where items that no longer exist"
156-
echo -n "Table: history orphaned items: "
157-
mysql_w "DELETE FROM history WHERE itemid NOT IN (SELECT itemid FROM items);"
158-
159-
echo -n "Table: history_uint orphaned items: "
160-
mysql_w "DELETE FROM history_uint WHERE itemid NOT IN (SELECT itemid FROM items);"
161-
162-
echo -n "Table: history_log orphaned items: "
163-
mysql_w "DELETE FROM history_log WHERE itemid NOT IN (SELECT itemid FROM items);"
164-
165-
echo -n "Table: history_str orphaned items: "
166-
mysql_w "DELETE FROM history_str WHERE itemid NOT IN (SELECT itemid FROM items);"
167-
168-
echo -n "Table: history_text orphaned items: "
169-
mysql_w "DELETE FROM history_text WHERE itemid NOT IN (SELECT itemid FROM items);"
170-
171-
echo -n "Table: trends orphaned items: "
172-
mysql_w "DELETE FROM trends WHERE itemid NOT IN (SELECT itemid FROM items);"
173-
174-
echo -n "Table: trends_uint orphaned items: "
175-
mysql_w "DELETE FROM trends_uint WHERE itemid NOT IN (SELECT itemid FROM items);"
156+
TABLES=(history history_uint history_log history_str history_text trends trends_uint)
157+
for table in "${TABLES[@]}"; do
158+
echo -n "Table: $table orphaned items: "
159+
mysql_w "DELETE FROM $table WHERE itemid NOT IN (SELECT itemid FROM items);"
160+
done
176161

177162

178163
echo "Delete records in the events table where triggers/items no longer exist"

0 commit comments

Comments
 (0)