#!/usr/local/bin/perl # # Name: sig-switch # # # Purpose: To randomly switch signature files daily # # Usage: Must be attached to a cron file using a cron tab. # # To switch it daily, your crontab must say: # 0 0 * * * /usr/local/bin/perl /absolute-path/sig-switch 2> /dev/null # where absolute-path is the whole pathname to this script # $basedir = $ENV{'HOME'}; $sigdir = "$basedir/.sigs"; #where dif sig files are kept. & bad_base unless (-e $sigdir); chdir($sigdir); @files = `ls -A`; #lists all files but . and .. $time = (time)%($#files+1); #close enough to random number srand [$time]; $todays = splice(@files, $time, 1); #pick the specific file chomp $todays; open (ORIG, "$sigdir/$todays") || die "Could not open file $ORIG\n"; @FILE = ; close(ORIG); open (COPY, ">$basedir/.signature") || die "Could not open file $COPY\n"; print COPY " "; #for some reason, one space is always missing print COPY "@FILE"; close (COPY); sub bad_base { print "I could not find the directory $sigdir\n"; exit; }