#!/usr/bin/perl -w # # Signatures should be seperated by a % on it's own line, eg: # # I like pies in the sky. # % # Milk and cookies are also nice. # # Especially cold milk. # % # JAPH # % # <% `uptime` %> # use strict; use Fcntl qw(:DEFAULT :flock); my $signature = "$ENV{HOME}/.signature"; # The FIFO. my $sigs_data = "$ENV{HOME}/.randsig.dat"; # Sigs go in here. my $pid_file = "$ENV{HOME}/.randsig.pid"; my $seperator = "%"; # See if the randsig.pid file exists, and whether or not # the file has a lock on it (just to check to see if randsig # is already running. If it is locked then exit gracefully. if (-e $pid_file) { sysopen PID_F, $pid_file, O_RDWR|O_CREAT or die "Couldn't open '$p +id_file': $!\n"; exit unless flock PID_F, LOCK_EX|LOCK_NB; print PID_F $$ + 1; # I know... but I'm just too lazy. } $0 =~ s#.*/##; print "$0: going into background.\n"; fork && exit; my ($l_mod, @sigs) = 0; while (1) { # Compare last modified timestamps of the sigs data file. my $n_mod = (stat($sigs_data))[9] || $l_mod; if ($n_mod != $l_mod) { $l_mod = $n_mod; @sigs = get_sigs(); } my $sig = $sigs[rand @sigs]; $sig =~ s#<%\s+(.*?)\s+%>#eval $1#eg; sysopen SIG_F, $signature, O_WRONLY|O_TRUNC or die "Couldn't open +'$signature': $!\n"; print SIG_F $@ ? $@ : $sig; close SIG_F; sleep 1; } sub get_sigs { sysopen SIGS_F, $sigs_data, O_RDONLY or die "Couldn't open '$sigs_ +data': $!\n"; local $/ = "\n$seperator\n"; return map { s#^\n##; s#%$##; s#\n$##g; $_ } <SIGS_F>; }

In reply to randsig by rendler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.