Operating System - HP-UX
1831479 Members
3411 Online
110025 Solutions
New Discussion

create 250 user ids in a go

 
SOLVED
Go to solution
Joyce Suganthy
Advisor

create 250 user ids in a go

Hi,

Do any of u genius out there have any script that can create 250 user id at a go.

I need to create them in a trusted system.

The ids should be like aba001, aba002 .....aba250

Thanks

Regards
Joyce
6 REPLIES 6
Vijaya Kumar_3
Respected Contributor
Solution

Re: create 250 user ids in a go

I think it is easy work.


Create a text file name "users"
aba001
aba002
aba003
...
aba250

Following piece of code will do:

for i in `cat users`
do
useradd $i
done


you may need to add any options to useradd command like Shell, Home directory etc.

Vijay
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
Ravi_8
Honored Contributor

Re: create 250 user ids in a go

Hi

As vijay said.

create a text file, with all uid's

#for i in 'cat '
do
useradd -g -d -s $i
done

will create all id's in a go.

never give up
Jakes Louw
Trusted Contributor

Re: create 250 user ids in a go

x=1
while [ "$x" -le 9 ]; do
echo "user aba00$x created"
useradd aba00$x
# increment x by 1
x=$(expr $x + 1)
done

Then do this for the ranges 010 to 099
(aba0$x)
and from 100 to 250
(aba$x)
Trying is the first step to failure - Homer Simpson
Hoefnix
Honored Contributor

Re: create 250 user ids in a go

adding to Ravi's post. Using the -m option will also create the users home-dir if it not exist.

useradd -g -d -m -s $i

HTH,
Peter Geluk
Jeroen Peereboom
Honored Contributor

Re: create 250 user ids in a go

Jakes,

For your information: using an appropiate shell, one can define a variable wirh leading zeroes, e.g.

typeset -Z3 userno

If you say: userno=$x, userno will become 001, 002, ...., 250.

This makes your script easier.

JP.
Jakes Louw
Trusted Contributor

Re: create 250 user ids in a go

Thanks, Jeroen.

Being almost geriatric, I'll have to write that one in my book....

Pity I can't assign you points.

Joyce, give him a couple, will you?
Trying is the first step to failure - Homer Simpson