my $message= "This message should not appear"; my $exitcode= $UNKNOWN; eval { my $dbh = undef; my $sth = undef; local $SIG{ALRM} = sub { if ($sth) { $sth->cancel(); } die $timeoutstr; }; alarm $timeout; $dbh = DBI->connect("dbi:Oracle:$sid", $user, $pass, { AutoCommit => 0, RaiseError => 0, PrintError => 1 } ); $sth = $dbh->prepare($stm) or do_exit($UNKNOWN, $dbh->errstr); $sth->execute() or do_exit($UNKNOWN, $dbh->errstr); if(my @row = $sth->fetchrow()) { # ... } else { $exitcode= $UNKNOWN; $message= "Did not get a result: " . ($DBI::errstr || ''); } $sth->finish(); $dbh->disconnect(); alarm 0; }; if ($@ and $@ eq $timeoutstr) { do_exit($CRITICAL, "Timeout after $timeout sec\n"); }