My Opera is closing 1st of March

M.I.T = Multimedia IT dept.

Subscribe to RSS feed

add ubuntu users massively via perl with pre-defined format

, ,

#!/usr/bin/perl

use strict;
my $user_file=$ARGV[0];
if (!$ARGV[0]) {
print "*** Usage: ./adduser.pl <user_file>\n";
print "*** The format of each line in the user_file is:\n";
print "*** username:password:shell:home_dir:group\n";
exit;
}

# Open user data file
open(FHD, "$user_file") || die "$!\n";
my $newuser_file = "$user_file.new";
open(FHE, "> $newuser_file") || die "$!\n";
my $groupfile="/etc/group";

# Change the format

while(<FHD>) {
chomp;
my ($username, $password, $shell, $home, $group)=split(/:/);
chomp(my $groupid=`cat $groupfile | grep ^$group | cut -d ":" -f3`);
my $newline="$username\:$password\:\:$groupid\:\:$home\:$shell";
print FHE "$newline\n";
}

close(FHD);
close(FHE);

`newusers < $newuser_file`;
February 2014
M T W T F S S
January 2014March 2014
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28