Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
It is currently adding data to the virtual file for the domain test1.com, but i want to be able to search and add data for another domain e.g test2.com. Ideas?my $username = "bob"; my $datafile = '/etc/postfix/virtual' ; my $req_addr = "$username\@test1.com" ; #Edit Postfix Virtual File my ( $name, $domain ) = $req_addr =~ /^([\w.-]+)(@[\w.-]+)$/ ; open FH, $datafile or die "Couldn't read $datafile: $!" ; my @virtual = <FH> ; close FH ; open FH, ">$datafile" or die "Couldn't write $datafile: $!" ; my $wrote_it = 0 ; for ( @virtual ) { print FH $_ ; if ( $_ =~ /test1.com/ && !$wrote_it ) { print FH "$req_addr\t$username\n" ; $wrote_it++ ; } } close FH ;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Postfix Virtual Edit Script
by edoc (Chaplain) on May 03, 2003 at 14:41 UTC |