aalneyperl has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: Help with HTML:Template
by roboticus (Chancellor) on Dec 07, 2007 at 13:42 UTC
    aalneyperl:

    To answer your questions:

    1) If you don't use a webserver, then you'll need to put the resulting output file on your machine and point the browser at that file, e.g., "file:///C:/WWWTemp/foo.html".

    2) You can run your perl program manually (such as from a DOS window) to regenerate your html file. If it's a simple status monitoring page, just run it as a scheduled job periodically. Then make a bookmark to your local status page, and you can check it whenever you like.

    3) HTML::Template tutorial is going to show you how to use it. It's a tool that lets you make HTML documents. It's not going to show you how to deliver the documents. It's a totally different job...

    4) You can place the files anywhere you like. The perl/cgi-bin is a convention used for web servers (as far as I know ... I've never made a perl web app before). If you're creating your own, you can make your own conventions.

    FYI: You could make it an active document such that you could have an HTML document on your machine, and have a bit of VBScript (if you're using IE) call your perl script to do the job.

    Hope this helps!

    ...roboticus

      Hi, Thanks roboticus ... As you can see from my code..i plan to use HTML::Template mondule..can you let me know where am i going wrong.