Skip to content

Instantly share code, notes, and snippets.

@kanazux
Created July 19, 2013 17:14
Show Gist options
  • Save kanazux/6040808 to your computer and use it in GitHub Desktop.
Save kanazux/6040808 to your computer and use it in GitHub Desktop.
Read data from pipe and send to mysql db
#!/usr/local/bin/python -u
import sys
import subprocess
conn = 'mysql -p123 -b webfilter'
ins_mysql = '-e "insert into ntable (url_str, elapsed_ms, size_bytes, ip, username) values (\'%s\', %s, %s, \'%s\', \'%s\')'
while 1:
fd=sys.stdin.readline()
itemAcc=fd.split()
subprocess.call(['%s %s' % (conn, ins_mysql, itemAcc[6], itemAcc[1], itemAcc[4], itemAcc[2], itemAcc[7])], shell=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment