1838374 Members
3125 Online
110125 Solutions
New Discussion

Re: Useradd

 
Prashant Zanwar_2
Occasional Advisor

Useradd

Hi,

I want to add users, I want to write a script for this.
Idea I want in this script, I have some uniq for each user, which I want to provide as input and also GID I want to provide as Input. , I want to keep according to OS selection. Can some one help please in this.
Uniq is of fixed length<10 digit>, i want to check length also first.
Please help, I know scripting, but not able to formulate properly.

thanks and regards
Prashant
4 REPLIES 4
Vijaya Kumar_3
Respected Contributor

Re: Useradd

echo "Enter user ID: "
read UID

echo "Enter user NAME: "
read UNAME

echo "Enter group ID: "
read GID

echo "Enter group name: "
read GNAME



groupadd -g $GID $GNAME
useradd -u $UID -o -g $GID $UNAME

-------
This is an overall logic for the script.
also you may need to check before adding the login, check for duplicate user ids.

Vijay
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
Prashant Zanwar_2
Occasional Advisor

Re: Useradd

Hi,

Thanks for reply Vijay,

I want something like below,

useradd -g gid -d /home/u$SSOID -s /bin/ksh -c "email, contact no" -m username

U have given good idea, can it be little more customised.

Regards
Prashant
Vijaya Kumar_3
Respected Contributor

Re: Useradd

Here is what "man useradd" says:


useradd
[-u uid [-o] ]
[-g group]
[-G group [, group...]]
[-d dir]
[-s shell]
[-c comment]
[-m [-k skel_dir]]
[-f inactive]
[-e expire]
login

Here, only is mandatory.

Hoe this helps
Vijay
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
Vijaya Kumar_3
Respected Contributor

Re: Useradd

So, inside a program, you can say

useradd -u $UID -o -g $GID -d /home/$LOGIN -s $SHELL -c $COMMENT $LOGIN

thanks
vijay
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com