Skip to content

Instantly share code, notes, and snippets.

@FingerLiu
Created June 4, 2017 04:25
Show Gist options
  • Save FingerLiu/61dae08b35ce060d82e87d0aae6888c7 to your computer and use it in GitHub Desktop.
Save FingerLiu/61dae08b35ce060d82e87d0aae6888c7 to your computer and use it in GitHub Desktop.
tcmpdump sql query
#!/bin/bash
#this script used monitor mysql network traffic.echo sql
tcpdump -i eth1 -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|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