# define variables
$user_remote_file='[email protected]:/usr/local/test/user.txt';
$local_path="/usr/local/test/";
$local_file="user.txt";
$user_list=$local_path . $local_file;
$dont_create=0;
# scp file from live node to local test directory
system('scp', $user_remote_file, $local_path);
# open user list for reading
open(user_list) or die("Could not open file $user_list!");
# loop for each user in list
while ($user = <user_list>) {
#print "$user";
# open passwd file to check whether user exists on this system
open FILE, "</etc/passwd";
while ($passwd_line = <FILE>) {# loop for each line in passwd file
#print "Into while loop for user $user";
#print $passwd_line;
# if the user exists
if ($passwd_line =~ m/$user/) {
$dont_create=1;
print "$user already exists on system!\n";
}
}
# if this user doesn't already have an account on the server
if ($dont_create==0) {
# create an account
system("useradd $user");
$dont_create=0;
}
|