Skip to content

Instantly share code, notes, and snippets.

@flores
Created July 5, 2011 19:09
Show Gist options
  • Save flores/1065603 to your computer and use it in GitHub Desktop.
Save flores/1065603 to your computer and use it in GitHub Desktop.
quick and dirty mysql grant checker
#!/usr/bin/perl -w
use strict;
#die "usage: $0 <mysql_server_hostname>" unless (@ARGV > 0);
#my $server=@ARGV;
#chomp $server;
#my @users=`ssh $server "echo \"select user,host from mysql.user;\" | /usr/bin/mysql"`;
my @users=`echo "select user,host from mysql.user" | /usr/bin/mysql`;
chomp @users;
my ($line, $user, $ip);
foreach $line (@users)
{
$line=~/^(\w+)\s+?(.+)/;
$user="$1";
$ip="$2";
#print "user $user ip $ip \n";
system "echo \"show grants for \'$user\'@\'$ip\';\" | /usr/bin/mysql";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment