Hi all, This is my script.
#!/usr/bin/perl # Check the health of a mysql server. use strict; use warnings; use Getopt::Long; use DBI; use HTML::Template; my %variables = (); my %status = (); my $resl = (); # -- # Print out the usage message # -- sub usage { print "usage: check_mysqlhealth.pl -H <host> -u <user> -p <passwor +d> \n"; print " Optional parameters:\n"; print " --port <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, $pas +sword, {'RaiseError' => 1}); }; if ($@) { my $status = $@; print 'CRITICAL: Connect failed with reason ' . $status . "\n"; exit 2; } #open the html template my $template=HTML::Template->new(filename => '/root/cookbook/perl/Mysq +lHC.tmpl'); &var(); &stat(); &repl(); sub var { my $sgv = $dbh->prepare("show variables"); $sgv->execute(); #my %variables = (); while (my ($keyword, $value) = $sgv->fetchrow_array()) { $variables{$keyword} = $value; } $sgv->finish(); } sub stat { my $sth = $dbh->prepare("show status"); $sth->execute(); #my %status= (); while (my ($keyword,$value) = $sth->fetchrow_array()) { $status{$keyword} = $value; } $sth->finish(); } sub repl { my $rs = $dbh->prepare("show status like 'slave_running'"); my $rrdbs = $dbh->prepare("show variables like 'read_rnd_buffer_size'" +); $rs->execute(); $rrdbs->execute(); while(my @vall = $rs->fetchrow_array()) { $template->param(Replication => $vall[1]); if($vall[1] eq 'ON') { print "The system is configured as Mysql Replication +SLAVE\n"; print " The following is the Slave Status\n"; my $mas_hos = $dbh->prepare("show slave status"); $mas_hos->execute(); while (my @val = $mas_hos->fetchrow_array()) { print "Slave_IO_State: $val[0]\n"; print "Master_host: $val[1]\n"; print "Slave_IO_Running: $val[10]\n" +; print "Slave_SQL_Running: $val[11]\n +\n"; #print "Seconds_Behind_master: $val[3 +3]\n"; } $mas_hos->finish(); } } } # send the obligatory Content-Type and print the template output print "Content-Type: text/html\n\n", $template->output;
and this my template file..
<html> <head><title>Mysql Health Check Script</title> <body>Replicatio +n Slave Status < TMPL_VAR NAME=Replication></body></html>
can anybody show me how to get the output of Replication slave. I got to know that i dont need a webserver to get the output. Question 1)How to get the out on a browser 2)how do i run the file or files or which file do i need to run and from where. 3) I had gone thru HTML::Template tutorial but i dint get these answers.. 4) Where do i need to place the files or..if i am not wrong do they have to placed under perl/cgi-bin somthing like that ..? Point my mistakes in the script... I am really sorry to ask such dum question..NEWBIE

In reply to Help with HTML:Template by aalneyperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.