Skip to content

Instantly share code, notes, and snippets.

@cgimenes
Last active July 21, 2017 13:19
Show Gist options
  • Save cgimenes/e28f57977fb437422c470c5256bdf833 to your computer and use it in GitHub Desktop.
Save cgimenes/e28f57977fb437422c470c5256bdf833 to your computer and use it in GitHub Desktop.
tcpdump MySQL traffic
#!/bin/bash
intf=$1
port=$2
if [ -z "${intf}" ]; then
intf="eth0"
fi
if [ -z "${port}" ]; then
port="3306"
fi
tcpdump -i ${intf} -s 0 -l -w - dst port ${port} | strings | perl -e '
while(<>) { chomp; next if /^[^ ]+[ ]*$/;
if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER|CALL)/i)
{
if (defined $q) { print "$q\n"; }
$q=$_;
} else {
$_ =~ s/^[ \t]+//; $q.=" $_";
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment