公司大批量添加×××用户,如果一个一个添加手就脱臼了 ...
主配置文件change.conf大体如下:
li.jie pptpd Li.jiE 192.168.1.1
dong.zhuo pptpd Dong.zhuO 192.168.1.2
.... ......
姓.名 服务名 姓.名(首大写,尾大写) 192.168.1.X
将员工的名字写到一文件中.name
li.jie
dong.zhuo
zhang.ye
再附上脚本:
脚本写的挺菜得,高手见笑了...
- #!/usr/bin/perl -w
- use warnings;
- use strict;
- =pod
- print << `EOC`;
- echo "......."
- echo "pptpd...."
- EOC
- =cut
- open CONF,"change.conf" or die "change.conf:$!\n";
- open NAME,"name" or die "name:$!\n";
- open FILE,">>change.conf" or die " >> change.conf:$!\n";
- chomp (my @name = <NAME>);
- chomp (my @conf = <CONF>);
- my @num;
- foreach (@conf){
- $_ =~ m/.*(?:\d+\.){3}(\d+)/;
- push(@num,$1);
- }
- my $num = $num[-1];
- my $IP = "192.168.1.";
- foreach my $name(@name){
- my $str = $name;
- $num ++;
- # $name =~ s/(\w)(\w+\.\w+)(\w)/\U$1\L$2\U$3/;
- $name .= uc(chop $name);
- print FILE "$str\tpptpd\t\"\u$name\"\t${IP}${num}\n" if (!(grep {/$str/i}@conf));
- }