V
Vahid
Hi all,
I have the following sub which adds a line '$assign' before the
last line in a file if 'add' is passed to the sub. I need a little
help to remove the line containing $new_user in the else part of the
sub. Also any suggestion in making the sub better looking is
appreciated.
Thanks,
Vahid.
sub qmail_alias {
$assign="=$new_user:$new_user:$new_uid:$new_gid:$def_qmail/alias:-:$new_user\n";
$var_qmail_alias = "/var/qmail/alias/.qmail-$new_user";
if ($DEBUG) { print "Assign value: $assign\n" };
my ($action) = @_;
open (ASSIGN_TMP,"> /tmp/assign.tmp") || die "Could not create
temporary assign file:$?";
open (ASSIGN, '</tmp/assign') || die "Could not open assign file:$?";
if ($action eq "add") {
print "Making mail alias for $new_user\n";
while ($INP_LINE = <ASSIGN>) {
print ASSIGN_TMP "$assign" if eof;
print ASSIGN_TMP $INP_LINE;
}
system("cp /tmp/assign.tmp /tmp/assign");
open (ALIAS, "> $var_qmail_alias") || die "$?";
if ($DEBUG) { print "Trying to write to: $var_qmail_alias\n" };
print ALIAS "&$new_email\n";
close ALIAS;
close ASSIGN;
close ASSIGN_TMP;
} else {
print "Deleting alias for $new_user.\n";
unlink $var_qmail_alias;
# need to remove $new_user from ASSIGN file.
}
}
I have the following sub which adds a line '$assign' before the
last line in a file if 'add' is passed to the sub. I need a little
help to remove the line containing $new_user in the else part of the
sub. Also any suggestion in making the sub better looking is
appreciated.
Thanks,
Vahid.
sub qmail_alias {
$assign="=$new_user:$new_user:$new_uid:$new_gid:$def_qmail/alias:-:$new_user\n";
$var_qmail_alias = "/var/qmail/alias/.qmail-$new_user";
if ($DEBUG) { print "Assign value: $assign\n" };
my ($action) = @_;
open (ASSIGN_TMP,"> /tmp/assign.tmp") || die "Could not create
temporary assign file:$?";
open (ASSIGN, '</tmp/assign') || die "Could not open assign file:$?";
if ($action eq "add") {
print "Making mail alias for $new_user\n";
while ($INP_LINE = <ASSIGN>) {
print ASSIGN_TMP "$assign" if eof;
print ASSIGN_TMP $INP_LINE;
}
system("cp /tmp/assign.tmp /tmp/assign");
open (ALIAS, "> $var_qmail_alias") || die "$?";
if ($DEBUG) { print "Trying to write to: $var_qmail_alias\n" };
print ALIAS "&$new_email\n";
close ALIAS;
close ASSIGN;
close ASSIGN_TMP;
} else {
print "Deleting alias for $new_user.\n";
unlink $var_qmail_alias;
# need to remove $new_user from ASSIGN file.
}
}