Bin Log Trimmer script dies if unable to connect to a server ?
I wrote a Perl script to trim the binary logs of several servers. The script walks multiple servers whose names are stored in an array. The script however will terminate immediately if it is not able to connect to a server - how do I get it handle the error and move on to the next server in the array instead of dying ? The code is below - your help is greatly appreciated - Thank you!
(Of course passwords, logins, server names have been changed for security purposes.)
#! /usr/bin/perl -w
# Gordon's DATE BASED BINLOG TRIMMER
use DBI;
# SERVER ARRAY BELOW...NEW SERVERS ARE ADDED HERE!!!
@server=("southdb101.mob.southvx.com","westdb1.san.westvx.com",
"southdb100.mob.southvx.com","southdb102.mob.southvx.com");
#THE SCRIPT FAILS TO COMPLETE EXECUTION IF A SERVER IS DOWN,HOW DO I HANDLE THIS SCENARIO
my $SendmailPath = 'c:/perl/bin/sendmail.exe';
# print $server[0];
foreach $server (@server)
{
my $binlog_date;
my $user_name1="tootie";
my $password1="purp!Jb9_JJ";
#replace the server name in the DSN variable with a variable that is built from an array
#loop through the array for all variable names
my $dsn1 = "DBI:mysql:mysql:"."$server"; #data source name
print $dsn1."\n";
my $pdate;
my $purge="PURGE MASTER LOGS BEFORE ";
my $purge_command;
# connect to database
my $dbh1 = DBI->connect ($dsn1, $user_name1, $password1,
{RaiseError=>0, PrintError=>1 AutoCommit => 1});
my $sth1 = $dbh1->prepare("select date_sub(current_timestamp, INTERVAL 15 DAY)");
$sth1-> execute();
while (my @ary1=$sth1->fetchrow_array ())
{$pdate= @ary1[0];
$purge_command="$purge\'$pdate\'";
}
my $sth2= $dbh1->prepare("$purge_command");
$sth2->execute();
#print $server;
}
Subject
Written By
Posted
Bin Log Trimmer script dies if unable to connect to a server ?
July 11, 2006 07:28AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.