I found this perl script someplace - its better than just calling /usr/games/fortune. 
because some of those fortunes can be rather long. 

On Wed, Oct 20, 1999 at 05:19:59PM +0000, Sean Rima wrote:
> Hi,
> 
> instead of defining a sig file, it is possible to use a tin like feature and
> use an external program to generate the sig file.
> 
> Sean
> -- 
> GPG ID (5.x) 92B9D0CF        
> To get my GPG (PGP 5.x) Key send me an empty
> email with retrieve as the subject
> Linux User: #124682 ICQ: 679813

-- 
<*krusty*> you are hating.com director of user taunting
#!/usr/bin/perl -w
#
# --- sig_rotate.pl ---
#
# Author:
#Jeffrey Watts
# Version:
#1.1
# Last Updated:
#27 April 99
# License:
#GPL
#
# As the filename suggests, sig_rotate.pl is a perl script that rotates
# signature files for you.  To use it, create a cron entry that runs this
# script at a reasonable interval, like every 5 minutes or so.  Then change
# the following variables to point to a directory which contains your
# signature files.  There should be nothing else in this directory except for
# signatures.  sig_rotate.pl's default behaviour is to rotate through the
# signatures, but it can also be set to do a random selection.


# ----------------- User-editable variables -----------------


# Both of these are relative to a user's home directory.  Change $SIG_HOME
# to point to the directory where you are keeping your signatures.  Most people
# won't need to change $SIG_FILE.

$SIG_HOME = ".signatures";
$SIG_FILE = ".signature";

# Change the following option depending on how you would like sig_rotate.pl to
# function.  ROTATE is the default setting, and it rotates through the files in
# your $SIG_HOME directory.  RANDOM randomizes the selection.

$METHOD = "ROTATE";


# --------------- End user-editable variables ---------------


$HOME = $ENV{'HOME'};

opendir(SIGS, "$HOME/$SIG_HOME");

@dirlist = sort(grep !/^\.\.?$/, readdir(SIGS));
$last = $#dirlist;

if ($METHOD eq "RANDOM") {
   srand;
   $item = int rand($last + 1);
   unlink("$HOME/$SIG_FILE");
   symlink("$HOME/$SIG_HOME/$dirlist[$item]", "$HOME/$SIG_FILE");
} else {
   $current = readlink("$HOME/$SIG_FILE");
   $current =~ s|$HOME/$SIG_HOME/||;

   for ($i = 0 ; (($i <= $last) && ($dirlist[$i] ne $current)) ; $i++) {}

   if ($i < $last) {
      unlink("$HOME/$SIG_FILE");
      symlink("$HOME/$SIG_HOME/$dirlist[++$i]", "$HOME/$SIG_FILE");
   } else {
      unlink("$HOME/$SIG_FILE");
      symlink("$HOME/$SIG_HOME/$dirlist[0]", "$HOME/$SIG_FILE");
   }
}

closedir(SIGS);

# end sig_rotate.pl

PGP signature

Reply via email to