#!/usr/bin/perl # Check the health of a mysql server. # use Getopt::Long; use DBI; my $Variable_name = ''; my $status = ''; # -- # Print out the usage message # -- sub usage { print "usage: check_mysqlhealth.pl -H -u -p \n"; print " Optional parameters:\n"; print " --port \n"; } $|=1; # -- # Parse arguments and read Configuration # -- my ($host, $user, $password, $port); GetOptions ( 'host=s' => \$host, 'H=s' => \$host, 'user=s' => \$user, 'u=s' => \$user, 'password=s' => \$password, 'p:s' => \$password, 'port=i' => \$port, ); if (!$host || !$user) { usage(); exit(1); } if (!$port) { $port = 3306; } my $totalTime = time(); # -- # Establish connection # -- my $state = "OK"; my $dbh; eval { $dbh = DBI->connect("DBI:mysql:host=$host;port=$port", $user, $password, {'RaiseError' => 1}); print "connected\n"; }; if ($@) { my $status = $@; print 'CRITICAL: Connect failed with reason ' . $status . "\n"; exit 2; } &open_report; sub open_report { my $sgv = $dbh->prepare("show variables"); $sgv->execute(); while (my $gv=$sgv->fetchrow_hashref()) { %MySQL_Variables{@gv[0]} = @gv[1];(is there a systax err here) Then to use a mysql item in perl use %MySQL_Variables{"uptime"} } $sgv->finish(); }