Monday, March 18, 2013
batch adding users with perl
#!/usr/bin/perl
# The format is username:password:shell:homedir:groupname
open FILE, $ARGV[0] or die "Cannot open file: $!";
foreach $line (@lines=<FILE>){
chomp($line);
($name,$pass,$shel,$dirc,$grup)=split(/:/,$line);
chomp($epas=`encrypt $pass`);
system "useradd -s $shel -d $dirc -g $grup -p '$epas' $name";
#print $epas,"\n";
$pattern="^".$name."\$";
open CHROOTFILE, "/etc/ftpchroot" or die "Cannot open file: $!";
open APPENDFILE, ">>/etc/ftpchroot" or die "Cannot append file: $!";
if(!grep (/$pattern/,<CHROOTFILE>)) {print APPENDFILE "$name\n";}
}
Labels:
perl
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment