[oak perl] Perl Scripts for Your Linux Environment

M. Lewis cajun at cajuninc.com
Sat Nov 30 23:23:38 CST 2002


George asked for scripts that are being used, so I figured I would start
the ball rolling with a 'tagline rotator' script. It's not very fancy,
but it does the job.

Start by putting your favorite taglines in a file somewhere. One per
line, like so:

This mail certified anthrax free.
rm -fr /bin/laden
shred -uzf /bin/laden

Next setup a cron job to run your script how ever frequently you want to
rotate your tagline. My cronjob looks like this:

0-59/5 * * * * /home/cajun/HOME/bin/makesig

The cron job just runs the script 'makesig' every 5 minutes. Oh, and
don't forget to setup your mailer to add your signature to all messages.
The script writes out the signature to ~/.signature

And lastly, here's the script: 
#!/usr/bin/perl -w

use strict;

my $debug=0;
my $home='/home/cajun';
my $siginfile="$home/HOME/sig/sigfile";
my $tearline="  \n";
my $uptime=`uptime`;
my $outfile="$home/\.signature";
my $linuxreg="  Linux Registered User #241685  http://counter.li.org\n";

open(INFILE,"$siginfile") or die "Can't open $siginfile :$!";
open(OUTFILE,">$outfile") or die "Sorry, but I can't write to $outfile
:$!";

my %hash;

while(<INFILE>){
  # build a hash with $. as key and $_ as value
  $hash{$.}=$_;
}

my $rand=rand($.);

my @body;

push (@body, $tearline);
push (@body, qq(  $hash{sprintf("%.0f", ($rand))}));
push (@body, $uptime);
push (@body, $tearline);
push (@body, $linuxreg);

if ($debug){
  print @body;
} else {
  print OUTFILE @body;
}

close INFILE;
close OUTFILE;

Thanks,
Mike

-- 
  
  Netnews is like yelling, "Anyone want to buy a used car?" in a crowded
theater.
  9:09pm  up 8 days, 20:48,  4 users,  load average: 1.13, 1.19, 1.09
  
  Linux Registered User #241685  http://counter.li.org




More information about the Oakland mailing list