[rt-users] A small script
Mitchell Henderson
mitchell at cts.wustl.edu
Wed Sep 3 14:14:33 EDT 2003
Hi,
A couple days ago I got 16000 Tickets created from SoBig and other things. I couldn't find a script to basicly batch erase a bunch of tickets so I wrote one. Figured someone else might have this problem so I'll share the script. It's very messy and i'm not 100% positive this is the right way to do it but it works for me, use at your own risk.
-- start script --
#!/usr/bin/env python
import MySQLdb
#THE USER NEEDS WRITE ACCESS!
USER=''
#PASSWORD
PASS=''
# WHERE THE SERVER LIVES
HOST=''
# NAME OF THE DATABASE
DB=''
#FILE YOU WANT TO LOG TO
LOGFILE=''
# file we'll log to
log = open(LOGFILE, 'w')
try:
dblink = MySQLdb.connect(user=USER, host=HOST, db=DB, passwd=PASS)
db = dblink.cursor()
except:
print "Couldn't get at the db"
sys.exit(1)
# you could put any query you wanted here as long as it returns the id,
# where Subject='BOUNCED MESSAGE' would probly be a good one
t = db.execute("SELECT id FROM Tickets WHERE status='dead';")
ids = db.fetchall()
log.write("%s entrys to be deleted" % str(int(len(ids))))
for i in range(len(ids)):
log.write("DELETE FROM Attachments where id=" + str(int(ids[i][0])) )
db.execute("DELETE FROM Attachments where id=" + str(int(ids[i][0])))
log.write("DELETE FROM Tickets where id=" + str(int(ids[i][0])) )
db.execute("DELETE FROM Tickets where id=" + str(int(ids[i][0])))
log.write("DELETE FROM Transactions where Ticket=" + str(int(ids[i][0])))
db.execute("DELETE FROM Transactions where Ticket=" + str(int(ids[i][0])))
log.write("DELETED TICKET ID %s\n" % str(int(ids[i][0])))
db.close()
log.close()
-- end script --
More information about the rt-users
mailing list