Commit 18719f55 authored by Anastasia Galkin's avatar Anastasia Galkin
Browse files

formating log file, log directory specified

parent e65002dd
The wp-check script checks statistics for a wordpress instance for the time frame of 1 day and logs those into file with a timestamp.
The check-wp script checks statistics for wordpress instances for the time frame of 1 day and logs those into file with a timestamp.
* new users
* new posts
* new pages
** Requirenments
For Centos:
```
yum install MySQL-python
```
Create the user and grant select privileges on the DB:
```
create user 'wp-check-user'@'your_server' identified by 'password';
grant select on wordpress_db.* to `wp-check-user`@`your_server`;
```
Let the check run every day at 5am
```
crontab -e
```
Insert
```
# check wordpress instances for news
0 5 * * * /usr/bin/python /opt/check-wp/check-wp.py
````
......@@ -5,13 +5,13 @@ import MySQLdb
from settings import *
log_name = '' + time.strftime("%Y%m%d_%H%M%S") + '_wordpress_stats.log'
log_name = LOG_DIR + time.strftime("%Y%m%d_%H%M%S") + '_wordpress_stats.log'
logfile = open(log_name, "w")
# Open database connection
for i, wp in WORDPRESS_DATABASES.items():
logfile.write("Wordpress: '{0}' ".format(i) + '\n')
logfile.write("Wordpress: '{0}' ".format(wp['NAME']))
nonews = True
db = MySQLdb.connect(wp['HOST'], wp['USER'], wp['PASSWORD'], wp['DATABASE'])
......@@ -25,6 +25,7 @@ for i, wp in WORDPRESS_DATABASES.items():
if int(count[0]) > 0:
nonews = False
logfile.write(' '+ wp['URL'] + '\n')
logfile.write("{0} new {1}\n".format(''.join(map(str, count)), j))
logfile.write(stats['header'] + "\n")
cursor.execute(stats['query'])
......@@ -33,9 +34,9 @@ for i, wp in WORDPRESS_DATABASES.items():
logfile.write(' | '.join(map(str, row)) + '\n')
if nonews:
logfile.write(' Nothing new here.')
logfile.write('.... \n')
logfile.write(' \n')
logfile.write('\n')
db.close()
......
LOG_DIR = ''
WORDPRESS_DATABASES = {
'default': {
'NAME': '',
'URL': '',
'USER': '',
'PASSWORD': '',
'HOST': '',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment