LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-05-2005, 05:02 AM   #1
mikz
Member
 
Registered: Sep 2004
Distribution: Slackware current
Posts: 109

Rep: Reputation: 15
Scripts and adduser


How can I do a bulk adduser for about 45 users where the password would be userID+66254? Are there any known scripts for this?
 
Old 03-05-2005, 05:47 AM   #2
born4linux
Senior Member
 
Registered: Sep 2002
Location: Philippines
Distribution: Slackware, RHEL&variants, AIX, SuSE
Posts: 1,127

Rep: Reputation: 49
try here:

http://www.linuxquestions.org/questi...adduser+script

this i got from google.com/linux:

#!/usr/bin/perl -w

use strict;

my %values; # will hold the values to fill in

# these are the known adduser switches
my %switches = ( home_dir => '-d', comment => '-c', group => '-G',
password => '-p', shell => '-s', uid => '-u');

# this location may vary on your system
my $command = '/usr/sbin/adduser ';

# for every switch, ask the user for a value
foreach my $setting (sort keys %switches, 'username')
{
print "Enter the $setting or press Enter to skip: ";
$values{$setting} = ;
chomp $values{$setting};
# if the user did not enter data, kill this setting
delete $values{$setting} unless length $values{$setting};
}

die "Username must be provided" unless exists $values{username};

# for every filled-in value, add it with the right switch to the command
foreach my $setting (sort keys %switches)
{
next unless exists $values{$setting};
$command .= "$switches{$setting} $values{$setting} ";
}

# append the username itself
$command .= $values{username};

# important - let the user know what's going to happen
print "About to execute [$command]";

# return the exit status of the command
exit system($command);

Last edited by born4linux; 03-05-2005 at 05:48 AM.
 
Old 03-05-2005, 06:39 AM   #3
mikz
Member
 
Registered: Sep 2004
Distribution: Slackware current
Posts: 109

Original Poster
Rep: Reputation: 15
I've looked at the link that you gave and have modified some of the following code which give me partially what I'm after:

I've modified the following code as such:

userprefix=test
totalusers=1
clear_passwd='test'
crypt_passwd=`openssl passwd -crypt $clear_passwd`
bashshell=
for((i=1;$i<=${totalusers};i +=1))
do
mkdir /home/${userprefix}${i}
useradd ${userprefix}${i} -d /home/${userprefix}${i} -g users -s /bin/bash -p $crypt_passwd
done

What do I need to add for it to give the same as the 'traditional' interactive adduser command? Which is usually the following:

bash-3.00# adduser test2
Login name for new user: test2
User ID ('UID') [ defaults to next available ]:
Initial group [ users ]:
Additional groups (comma separated) []:
Home directory [ /home/test2 ]
Shell [ /bin/bash ]
Expiry date (YYYY-MM-DD) []:

New account will be created as follows:

---------------------------------------
Login name.......: test2
UID..............: [ Next available ]
Initial group....: users
Additional groups: [ None ]
Home directory...: /home/test2
Shell............: /bin/bash
Expiry date......: [ Never ]

This is it... if you want to bail out, hit Control-C. Otherwise, press
ENTER to go ahead and make the account.
Creating new account...

Changing the user information for test2
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Changing password for test2
Enter the new password (minimum of 5, maximum of 127 characters)
Please use a combination of upper and lower case letters and numbers.
New password:
Re-enter new password:
Password changed.
Account setup complete.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
VPN: Debian Scripts -> Mandriva 2006 Scripts Undefined Mandriva 0 11-30-2005 12:10 PM
adduser 64bitPlaya Slackware 2 08-13-2004 05:05 PM
adduser trophy Red Hat 1 05-01-2004 09:11 AM
Adduser scripts?? Copenhagen Cowboy Linux - General 13 12-09-2003 08:22 AM
adduser teqno Linux - Newbie 5 12-08-2003 12:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration