i've written a script that builds a new /etc/aliases file by pulling in
customer include files from /etc/mail/include/aliases/<filename> where the
filename is customer specific.

the script builds a new /etc/aliases that is composed all all the customer
pieces. this happens properly, however, when i attempt to restart sendmail
and run newaliases from within the same script, the newaliases output
shows 0 aliases created. if i take the same commands and insert them into
another perl script that is run directly after the first script which
builds the new /etc/aliases, everything seems fine

is there a reason why this same script can't do both jobs?
thanks!! -charles


the script:

#!/usr/bin/perl -w

# $Id: mkmail.pl,v 1.16 2001/07/01 18:48:40 root Exp $

use strict;

#definitions and declarations
my $each;
my $inc = "/etc/mail/include";
my $vtmp = "/etc/mail/.virtusertable.tmp";
my $vbak = "/etc/mail/.virtusertable.bak";
my $atmp = "/etc/mail/.aliases.tmp";
my $abak = "/etc/mail/.aliases.bak";
my $vrun = "/etc/mail/virtusertable";
my $arun = "/etc/aliases";

#test to see if temp file exists. empty contents
if ( -e $atmp ) {
  unlink $atmp;
}

if ( -e $vtmp ) {
  unlink $vtmp;
}

#copy the production virtusertable file to backup
rename $arun, $abak;
rename $vrun, $vbak;

#get list of include files
opendir VDH, "$inc/virtuser" or die "Cant open virtuser include directory
$!\n";my @vcontents = readdir VDH;
closedir VDH;

opendir ADH, "$inc/aliases" or die "Cant open aliases include directory
$!\n";
my @acontents = readdir ADH;
closedir ADH;

#i sort the contents so that they will be alphabetically listed in
#the final production file
@acontents = sort @acontents;
@vcontents = sort @vcontents;

#change into the virtuser include directory
chdir "$inc/virtuser" or die "Cant change to virtuser include directory
$!\n";

#write contents of include files into the tmp virtusertable
open VWF, ">>$vtmp" or die "Cant open virtuser temp file $!\n";
for $each(@vcontents) {
  next if ( $each eq "." );
  next if ( $each eq ".." );
  open FH, $each or die "Cant open virtuser include file $!\n";
  print VWF "\#\#\# $each \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\n";
  print VWF <FH>;
  close FH;
}
close WF;

#change into the aliases include directory
chdir "$inc/aliases" or die "Cant change to aliases include directory
$!\n";

#write contents of include files into the tmp aliases
open AWF, ">>$atmp" or die "Cant open aliases temp file $!\n";
for $each(@acontents) {
  next if ( $each eq "." );
  next if ( $each eq ".." );
  open FH, $each or die "Cant open aliases include file $!\n";
  print AWF "\#\#\# $each \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\n";
  print AWF <FH>;
  close FH;
}
close WF;

#move the tmp file into production
rename $vtmp, $vrun;
rename $atmp, $arun;

#restart sendmail
system("/etc/rc2.d/S80sendmail restart");
system("/usr/bin/newaliases");

Reply via email to