公司需要用apache简单认证功能为客户创建帐号和密码(密码需要随机生成),所以小弟用perl编了一个非常简单的脚本来完成这个功能。
#!/usr/bin/perl
use strict;
use warnings;
my $username;
if ($ARGV[0]){
$username = $ARGV[0];
}
else{
print "please input username:";
$username = <STDIN>;
chomp($username); #丢弃最后的回车键
}
if ($username){
my $maxLenth=8;
my @a = (0..9,'$','%','a'..'z','A'..'Z','-','+','_');
my $password = join ('',map ($a[int rand @a],0..($maxLenth-1))); #生成8位随机数的核心
print "$username\t$password\n";
`/usr/bin/htpasswd -b /data/www/htdocsssl/SOFTWAREUPGRADE/security/.htpasswd $username $password`;
}