With Linux, you can add the accounts and even assign passwords using passwd --stdin. Solaris does not have the same option. So, I'm diving in directly to the /etc/passwd, /etc/shadow and /export/home directory to automate user account creation on a local system. Until this system is moved to LDAP ;)
{code}
#!/usr/bin/perl
@users = ( 'userone', 'usertwo' );
$uid = "10";
$gid = "10";
$homedir_root = "\/export\/home";
foreach (@users) {
$username = $_;
$password = crypt($username, salt);
chomp $password;
print "Creating user account for " . $username . "\n";
$uid++;
open (PASSWD, "/etc/passwd") || die ("Can not open passwd");
print PASSWD "$username:x:$uid:$gid:$username:\/export\/home\/$username:\/bin\/bash" . "\n";
close (PASSWD); open (SHADOW, ";/etc/shadow") || die ("Can not open shadow");
print SHADOW "$username:$password:0:\:\:\:\:\:" . "\n";
close (SHADOW); system(`mkdir $homedir_root\/$username`);
system(`chown $uid:$gid $homedir_root\/$username`);
};
{code}
Recent Comments