I have a simple Perl script which runs as a Linux daemon using an infinite loop. It connects to a database every 10 seconds to execute a process.
while (1)
{
# THIS LINE WILL KILL THE SCRIPT IF IT FAILS
my $DB=DBI->connect("dbi:Sybase:server=myserver","user","password");
. . . do something . . .
sleep (10);
}
I have two questions:
- If the DB is unavailable, how I can keep the script running?
- Can I add an exception handler to send me an email or log an error?