美好的一天! 我只想帮助解决一个问题。我在CentOS Linux命令行中创建了students.txt列表:
said:123456
taha:456789
我创建了有脚本的perl文件:
#!/usr/bin/perl
$filename = 'students.txt';
open(FILE, $filename);
while(<FILE>)
{
chomp;
($user, $passcode) = split(/:/, $_);
system "useradd $user -m -p $passcode";
}
close FILE;
print "Users are created successfully :) \n";
运行perl文件后,它会添加用户名,但不会添加密码。我也是Perl的新手。提前谢谢。
答案 0 :(得分:0)
#!/usr/bin/perl
$filename = 'students.txt';
open(FILE, $filename) or die $!;
while($line = <FILE>) {
chomp $line;
($user, $passcode) = split(/:/, $line);
system "useradd $user -m";
}
close FILE;
system "chpasswd < students.txt";
print "Users are created successfully :) \n";