Suresh Ramasubramanian rearranged electrons thusly:
> Better use perl ... I posted a perl script for this to LIH sometime back -
> search the archives. (dont have it right now, I'm on a doze box at home) :(
this is the script - change your domain from example.com (and I dont think this
is too secure for general use ... I su to root and run it manually)
--suresh
#!/usr/bin/perl
if ($#ARGV < 1)
{
print "Usage : adduser <USER> <PASSWORD> [<DOMAIN>]" . "\n";
exit 999;
}
my $DOMAIN = "example.com";
if (@ARGV[2] ne "")
{
$DOMAIN = @ARGV[2];
}
my $username = @ARGV[0];
my $password = @ARGV[1];
$passdir = "/home/popmail/etc/passwd";
open(PASSFILE,"$passdir") || die "Cannot Open File $passdir";
@lines = <PASSFILE>;
close(PASSFILE);
$found = 0;
open(PASSFILE,">$passdir");
foreach $line(@lines){
if($line =~ /^$username/g){
$newpass = crypt($password, substr($username,0,1) . substr($username,
length($username) - 1,1));
print PASSFILE "$username:$newpass\n";
$found = 1;
}
else{
print PASSFILE "$line";
}
}
if ($found == 0) {
$newpass = crypt($password, substr($username,0,1) . substr($username,
length($username) - 1,1));
my $userID="501:501::";
print PASSFILE "$username:$newpass:$userID\n";
}
close(PASSFILE);
exit;
--
Suresh Ramasubramanian <--> mallet <at> efn <dot> org
EMail Sturmbannfuhrer, Lower Middle Class Unix Sysadmin
----------------------------------------------
An alpha version of a web based tool to manage
your subscription with this mailing list is at
http://lists.linux-india.org/cgi-bin/mj_wwwusr