use strict; use warnings; use WWW::Curl::Easy; use POSIX qw(pause); use Time::HiRes qw(time alarm setitimer sleep ITIMER_REAL); use Getopt::Std; ### Process command line args usage() if defined $ARGV[0] and $ARGV[0] eq "--help"; getopts('hvV') or usage(); # process [interval [count]], my ( $interval, $loop_max ); if ( defined $ARGV[0] ) { $interval = $ARGV[0]; $loop_max = defined $ARGV[1] ? $ARGV[1] : 2**32; usage() if $interval == 0; } else { $interval = 1; $loop_max = 1; } ### Variables my $loop = 0; # current loop number # how often do we trigger (seconds)? my $first_interval = $interval; # signal handler is empty $SIG{ALRM} = sub { }; # first value is the initial wait, second is the wait thereafter setitimer( ITIMER_REAL, $first_interval, $interval ); my $http = WWW::Curl::Easy->new(); if (&WWW::Curl::Easy::version() !~ /ssl|nss/i) { die "No SSL support"; } # Get the results while (1) { my $url = "http://kronometrix.org/"; $http->setopt(CURLOPT_URL, $url); my $retcode = $http->perform(); ## Get the results my $response = $http->getinfo(CURLINFO_HTTP_CODE); if ($retcode == 0) { print "Ok, Status: $response\n"; } else { print "Error, Status: $response\n"; } ### Check for end last if ++$loop == $loop_max; ### Interval pause; # sleep $interval; }