-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_wp_options.py
More file actions
executable file
·47 lines (34 loc) · 1.28 KB
/
check_wp_options.py
File metadata and controls
executable file
·47 lines (34 loc) · 1.28 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
#!/usr/bin/env python
"""
check_wp_options
Given a file of MySQL database names and a root MySQL password, checks the row count of wp_options.
Issues a WARNING message if more than 10K rows exist in the table so you can grep the output for WARN.
"""
import sys
import os
import subprocess
def usage():
print "Usage: {0} [database_file] [mysql_root_pw]".format(sys.argv[0])
sys.exit(1)
if len(sys.argv) < 3:
usage()
db_file = sys.argv[1]
mysql_root_pw = sys.argv[2]
with open(db_file) as f:
databases = f.readlines()
for database in databases:
database = database.strip()
command_line = "/usr/bin/mysql -u root -p{0} {1} -e".format(mysql_root_pw, database)
params = command_line.split(" ")
params.append("SELECT COUNT(*) FROM wp_options");
print "[{0}] Checking database {0}".format(database)
result = subprocess.Popen(params, stderr=subprocess.PIPE, stdout=subprocess.PIPE).communicate()
if "ERROR 1146 (42S02) at line 1" in result[1]:
print "[{0}] This is not a valid WordPress database; skipping".format(database)
else:
lines = result[0].split("\n")
row_count = int(lines[1])
print "[{0}] wp_options table has {1} row(s)".format(database, row_count)
if row_count > 10000:
print "[{0}] WARNING: wp_options table has many rows!".format(database)
print "I_DONE: Complete"