Skip to content

Instantly share code, notes, and snippets.

@why404
Created April 17, 2009 02:11
Show Gist options
  • Save why404/96813 to your computer and use it in GitHub Desktop.
Save why404/96813 to your computer and use it in GitHub Desktop.
#!/bin/bash
tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings | perl -e '
while(<>) { chomp; next if /^[^ ]+[ ]*$/;
if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER)/i) {
if (defined $q) { print "$q\n"; }
$q=$_;
} else {
$_ =~ s/^[ \t]+//; $q.=" $_";
}
}'
#refer http://www.mysqlperformanceblog.com/2008/11/07/poor-mans-query-logging/
#link http://tuxtraining.com/2009/04/14/tcpdump-cheat-sheet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment