#!/usr/bin/perl use strict; use warnings; use DBI; $| = 1; my $db = "your database here"; my $host = 'your.server.here'; my $port = 3306; my $dsn = "dbi:mysql:database=$db;host=$host;port=$port"; my $user = 'your user name here'; my $pass = 'your password here'; my $dbh = DBI->connect($dsn, $user, $pass); print "Connection made. Sleeping so you can disable the network: "; sleep(3); print "done\n"; eval { local $SIG{ALRM} = sub {die "timeout\n"}; alarm(1); eval { print $dbh->ping() ? "ping succeeded\n" : "ping failed\n"; }; alarm(0); die "$@\n" if $@; }; if ($@) { die "$@\n" if $@ !~ /^timeout/; print "ping failed (timeout)\n"; }