#!/usr/bin/perl -w ################################ # This script creates .forward # # and .vacation.msg files # # for e-mail autoreplying # # used by Exim # # # ############################### use strict; use diagnostics; my %users = ( #username leaves on is b +ack on user => {van => [17,7,5], tm => [13,8,5] +, }, ); my $vacstd = '/home/user/scripts/.vacation.msg'; #standard away mes +sage my $fwdstd = '/home/user/scripts/.forward'; #standard Exim fil +ter file -e $vacstd or die("Needed file \"$vacstd\" not found; Quitting."); -e $fwdstd or die("Needed file \"$fwdstd\" not found; Quitting."); foreach(keys %users) { my $crntuser = $_; #current user my @d = localtime(time); #date info it needs for comparing my $sdate = join('-',@{$users{$crntuser}{van}}); #leaving dat +e my $edate = join('-',@{$users{$crntuser}{tm}}); #returning d +ate my $cdate = join('-',$d[3],$d[4]+1,$d[5]-100); #current dat +e my @udata = getpwnam($crntuser); #user login +pass uid gid for chown later my $fwdnew = "/home/$_/.forward"; #filename fo +r fresh Exim filter file if($edate eq $cdate) { #Is the returning date today? if(-e $fwdnew) { #Does the fresh Exim filter file exist? unlink $fwdnew; #then delete it print "User Scrntuser : File $fwdnew removed due to reac +hed target end date $edate ($cdate); Quitting."; exit 0; #and we're done for today. } } if($sdate ne $cdate) { print "User $crntuser : Target start date $sdate ($cdate) not +yet reached."; #next user if we're not ready yet next; } my $vacnew = "/home/$_/.vacation.msg"; #fresh vacation message + file print "Creating .vacation file for user $_\n"; if(-e $vacnew) #Does it already exist? then go on. { print "File \"$vacnew\" already exists? Wut??\n" ; } else { open VACSTD,$vacstd #open standard vacation file for readin +g or die("Unable to access standard vacation file \"$v +acstd\"; Quitting."); open VACNEW,">$vacnew" #open fresh vacation file for writing or die("Unable to access fresh vacation file \"$vacnew\"; + Quitting."); while(<VACSTD>) { s/_DATE_FROM_/$sdate/g; #replace start date s/_DATE_UNTIL_/$edate/g; #replace return date print VACNEW $_; #save to fresh vacation file } close VACSTD; close VACNEW; print "File \"$vacnew\" successfully written.\n"; } die("Unable to create \"$fwdnew\"; Quitting.") if system('cp',$fwdstd,$fwdnew) == -1; #kill off if we can't +copy the exim filter file to the fresh copy. die('Error changing file permissions; Quitting.') if chown $udata[2],$udata[3],[$vacnew,$fwdnew] <2; #kill off if we c +an't set user permissions on fresh filter # and vacatio +n message file. print "File \"$fwdnew\" successfully written.\n"; #Otherwise we'd have + die()d so this can be displayed ok :) } #and we're done.

In reply to Autoresponder automator by jkva

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.