Rather than using a browser such a Firefox you should use an HTTP client library such as HTTP::Tiny or LWP::UserAgent.
For exmaple:
#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';
use HTTP::Tiny;
my $Client = HTTP::Tiny->new();
my @urls = (
'http://www.yahoo.com',
'https://www.google.com',
'http://nosuchsiteexists.com',
);
for my $url (@urls) {
my $response = $Client->get($url);
say $url, ": ", $response->{status};
}
Which outputs:
alex@yuzu:~$ ./return_status.pl
http://www.yahoo.com: 200
https://www.google.com: 200
http://nosuchsiteexists.com: 599
If you want to correctly recognise redirect status codes (3XX) you would have to set the max_redirect parameter to 0.
alex@yuzu:~$ perl -MHTTP::Tiny -E 'say HTTP::Tiny->new(max_redirect => 0)->get("http://www.nestoria.co.uk/soho")->{status};'
301
If all you care about is success then the response hashref contains a 'success' field which will be true on success and false on failure.
alex@yuzu:~$ perl -MHTTP::Tiny -E 'say HTTP::Tiny->new()->get("http://www.google.com")->{success};'
1
HTTP::Clientmodule (or LWP) instead. That will allow you to check the return codes but will not display any UI to the user. Do you really need the entire browser to be launched? Please explain more clearly what you're trying to accomplish.checkbot