1834156 Members
2383 Online
110064 Solutions
New Discussion

Re: user add

 
mahesh_24
Occasional Advisor

user add

I want to write a shell script using sed and awk which automatically and adds and modifies, delete user ..any ideas ???
6 REPLIES 6
Mark Grant
Honored Contributor

Re: user add

Probably best to use the "useradd" command.

It is difficult to post a script here, if you don't want to use "useradd", as so many people would do this in different ways.

I suspect the best thing would be do a short script to keep track of the next free UID and put that as a variable to the "useradd" command.

Never preceed any demonstration with anything more predictive than "watch this"
Robert-Jan Goossens
Honored Contributor

Re: user add

Hi Mahesh,

Take a look at the command useradd and userdel.

Hope it helps,

Robert-Jan.
mahesh_24
Occasional Advisor

Re: user add

does anbody has any script to see the used id alraedyu assigned and chose the free one .I want to add the uer ids in nis not using the useradd command ..so have to parse through the passwd file .
twang
Honored Contributor

Re: user add

The following script I use recently to add many users at a time:

#!/bin/sh
for i in `cat /tmp/newusers.lst`
do
USER=`echo $i | awk -F":" '{print $1}'`
UID=`echo $i | awk -F":" '{print $2}'`
GROUP=`echo $i | awk -F":" '{print $3}'`
DIR=`echo $i | awk -F":" '{print $4}'`
SHELL=`echo $i | awk -F":" '{print $5}'`
/usr/sbin/useradd -u $UID -g $GROUP -d $DIR -s $SHELL $USER
if [ $? -eq 0 ]
then
/usr/bin/passwd $USER
fi
done
mahesh_24
Occasional Advisor

Re: user add

My requirement is to change the existing NIS file eg.
user field to = Yusername
passwd =*.NP*
comment = user disabled
shell= /bin/false

i have written a sed script which is changing the first field only ..now i wanna change passwd , comment and shell field.I am pastiniog the script below ..for suggestions /modifications ..

#!/usr/bin/ksh
#usage :scriptname passwdfilename
set -x
for x
do
echo "enter the user name \c"
read user1
echo "the user name to be disabled is $user1"
grep "^${user1}:" $x
if [ $? -eq 0 ]
then
sed '/^'$user1':/ {
s/'$user1'/X'$user1'/
}' $x
else
echo "please enter the correct user name as $user1 does not exist in the $x"
fi
done
~



~
Steven E. Protter
Exalted Contributor

Re: user add

I'm attaching my version.

You'll see all kinds of cool code, some of it commented.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com