Everyone,
thanks for the help with the script.  I took everyone's input and
rewrote it.

#!/usr/bin/perl
use strict;
use warnings;

use DBI;

my( $dbname ) = "BACKUP";
my( $mysqluser ) = "bob";
my( $mysqlpasswd ) = "bobspasswd";
my( $dbh, $sth, $rc );
my( @failedCon, $var, $name, @names );

#these variables will be passed to subroutine in main program.
my( $hostId ) = "543";
my( $biggyFlag ) = "0";
my( $hostDirFlag ) = "1";


$dbh = DBI->connect( "DBI:mysql:database=".$dbname, $mysqluser,
$mysqlpasswd, {RaiseError => 1 } ) or die "Cannot connect to database:
$!";

#first check for failed attempts

$sth = $dbh->prepare( qq{ SELECT failedConAttempt FROM tblControl WHERE
hostId="$hostId" } );
$sth->execute ();
$sth->bind_columns( \$var );
while  ( $sth->fetch ) { 
    
    push @failedCon, $var;
    
}
$sth->finish ();

print "backup failed to connect to $hostId: $failedCon[0] times.\n";


#grab information

if ( $failedCon[0] == 0 ) {
    $sth = $dbh->prepare ( q{
        SELECT name FROM tblProcess
        WHERE biggy_flag="$biggyFlag" AND hostId="$hostId" AND
hostDirFlag="$hostDirFlag"
    } );
    $sth->execute ();
    $sth->bind_columns( \$name );
    while ( $sth->fetchrow_array () ) {
        push @names, $name;
    }
    $sth->finish ();
    print "Looks like a first: @names\n";
}else{
    $sth = $dbh->prepare ( q{
        SELECT name FROM tblProcess
        WHERE biggy_flag="$biggyFlag" AND hostId="$hostId" AND
hostDirFlag="$hostDirFlag" AND status="In-Progress" OR status="Queued"
    } );
    $sth->execute ();
    $sth->bind_columns( \$name );
    while ( $sth->fetchrow_array () ){
        push @names, $name; 
    }
    $sth->finish ();
    print "Looks Like we have been here before:@names\n";
}

$rc = $dbh->disconnect;
exit (0);

Everything works as it should.  Thanks again....


chad





Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to