Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- #
- # Execute via ctrontab:
- # */10 * * * * mattermost /opt/mattermost/mmdel.py
- import psycopg2
- import os
- datadir = "/opt/mattermost/data"
- # Try to connect
- try:
- conn=psycopg2.connect(database="mattermost", user="mattermost", password="PASSWORD", host="localhost")
- except Exception as e:
- print ("I am unable to connect to the database." + str(e))
- cur = conn.cursor()
- try:
- cur.execute("""SELECT path, posts.deleteat
- FROM fileinfo
- INNER JOIN posts ON fileinfo.postid=posts.id
- WHERE posts.deleteat > 0;""")
- except Exception as e:
- print ("Select failed" + str(e))
- rows = cur.fetchall()
- for row in rows:
- fileName = os.path.join(datadir, row[0])
- if(os.path.isfile(fileName)):
- print ("deleting ", fileName)
- os.remove(fileName)
Add Comment
Please, Sign In to add comment