#!/usr/bin/python
import
MySQLdb
import os
import sys
fileHandle = open ( '/var/log/13-11-05.log' )
try:
conn=MySQLdb.connect(host='ipAddress',user='developer',passwd='developer',db='test',port=3306)
mycursor = conn.cursor()
for line in fileHandle.readlines():
startIPPos = line.index('(')
endIPPos = line.index(')')
ipAddr = line[startIPPos+1:endIPPos]
startUPos = line.index('#####')
endUPos = line.index('pts')
uName = line[startUPos+5:endUPos]
mycursor.execute('insert into MyRecord (name,ip,record) values(%s,%s,%s)',(ipAddr,uName,line))
conn.commit()
except MySQLdb.Error,e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
mycursor.close()
conn.close()
fileHandle.close()