All pastes #435754 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-04-12 03:38 UTC
rendered paste body
#!/usr/bin/perl -w
use strict;
use integer;
use Fcntl qw(:flock);

my $SIGFILE = '/home/luciano/.thunderbird/taglines/firma.txt';
my $LCKFILE = '/home/luciano/.thunderbird/taglines/firma-lock.txt';
my $SIGPROG = "fortune";
my $SIGTAG = "(Not so) Random fortune:\n";
my $timeout = 90;

# test before forking
open(LCKFILE, $LCKFILE) or die $!;
flock(LCKFILE, LOCK_EX|LOCK_NB) or exit 0;

# the following is totally silent on errors!
(fork == 0) or exit;

my $SIGNATURE;

while (1)
{
    $SIGNATURE = `$SIGPROG`;
    open(SIGNATURE, ">$SIGFILE") or die $!;
    printf SIGNATURE ("%s%s", $SIGTAG, $SIGNATURE);
    close SIGNATURE or die $!;
    sleep $timeout;
}