#!/usr/bin/perl

@contents = <STDIN>;
$last = $contents[$#contents];
$rc = 0;

if ($last!~/^HTTP OK/) {
    $file = $ARGV[0];
    open(FILE,">$file");
    foreach (@contents) {
        print FILE $_;
    }
    close(FILE);
    if ($last=~/^HTTP WARNING/) { $rc = 1; }
    elsif ($last=~/^HTTP CRITICAL/) { $rc = 2; }
    else { $rc = 3; }
}

print $contents[$#contents];

exit($rc);
