#! /usr/bin/perl

use strict;
use warnings;

=head1 NAME

crashlog.pl - put timestamps to a file

=head1 SYNOPSIS

In your crontab,

  @reboot ( ./crashlog.pl >> crashlog.txt & ) &

=head1 DESCRIPTION

Put a timestamp in a file every couple of minutes.  Let's find out
when the machine crashes, and whether that correlates with anything.

=head1 REQUIREMENTS

You need a cron(8) that handles the '@' extensions, or some other
means of starting it.

=cut

$| = 1;
stamp("startup");

$SIG{INT} = $SIG{TERM} = sub { exit; };

while (1) {
    sleep 120;
    stamp();
}

END {
    stamp("shutdown");
}

sub stamp {
    print join "\t", time(), scalar localtime(), @_;
    print "\n";
    system("sync &");
}

