Linux 4 All

Best Linux tricks source

Posts in the perl category

Here is a quick trick for using tcpdump to get all MySQL queries running on a server:

tcpdump -i $INTERFACE -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.=" $_";
  }
}'

I think I got this from Percona website