Just thought that I would add a couple of extras to Kwan's script..
But I am not sure if the password thingy works correctly yet maybe
someone will have something better.. anyway
here it is..
#!/bin/bash
IFS=$'\n'
for item in `cat /etc/passwd`; do
USERNAME=`echo $item | cut -d: -f1`
USERID=`echo $item | cut -d: -f3`
GROUPID=`echo $item | cut -d: -f4`
COMMENT=`echo $item | cut -d: -f5`
USERDIR=`echo $item | cut -d: -f6`
USERSHL=`echo $item | cut -d: -f7`
if [ "$USERID" -gt "499" ] && [ "$USERNAME" != "nobody" ] ; then
echo groupadd -g ${GROUPID} ${USERNAME}
echo useradd -u ${USERID} -g ${GROUPID} -c \"${COMMENT}\" \
-d ${USERDIR} -s ${USERSHL} ${USERNAME}
PASSWD=`grep ${USERNAME}: /etc/shadow | cut -d: -f2`
echo usermod -p \"$PASSWD\" ${USERNAME}
fi
done
On Wed, 2003-06-11 at 02:53, Alan Wilter Sousa da Silva wrote:
> Hi!
>
> Thank you for your script. I had to do some modifications, as follow:
>
> #!/bin/bash
>
> # kwan:x:500:1000:Kwan Lowe:/home/kwan:/bin/bash
> IFS=$'\n'
>
> for item in `cat /etc/passwd`; do
> USERNAME=`echo $item | cut -d: -f1`
> USERID=`echo $item | cut -d: -f3`
> GROUPID=`echo $item | cut -d: -f4`
> COMMENT=`echo $item | cut -d: -f5`
> USERDIR=`echo $item | cut -d: -f6`
> USERSHL=`echo $item | cut -d: -f7`
> echo groupadd -g ${GROUPID} ${USERNAME}
> echo useradd -u ${USERID} -g ${GROUPID} -c \"${COMMENT}\" -d
> ${USERDIR} -s ${USERSHL} ${USERNAME}
> done
>
> Now I wonder how can I do to set password automatically.
>
> On 9 Jun 2003, Kwan Lowe wrote:
>
> > On Mon, 2003-06-09 at 19:25, Mark Williamson wrote:
> > > Hi Kwan,
> > >
> > > Nice looking script, but did you try it? But it seems to have problems,
> > > getting the fields mixed up..
> > >
> >
> > Nope, just wrote it on the spot.. Sorry...
> > Lemme see..Try this...
> >
> >
> >
> > #!/bin/bash
> >
> > # kwan:x:500:1000:Kwan Lowe:/home/kwan:/bin/bash
> > IFS=$'\n'
> >
> > for item in `cat /etc/passwd`; do
> > USERNAME=`echo $item | cut -d: -f1`
> > USERID=`echo $item | cut -d: -f3`
> > GROUPID=`echo $item | cut -d: -f4`
> > COMMENT=`echo $item | cut -d: -f5`
> > USERDIR=`echo $item | cut -d: -f6`
> > USERSHL=`echo $item | cut -d: -f7`
> >
> > echo useradd -u ${USERID} -g ${GROUPID} -c ${COMMENT} \
> > -d ${USERDIR} -s ${USERSHL}
> > ${USERNAME}
> > done
> >
> >
> >
> >
> >
Want to buy your Pack or Services from MandrakeSoft?
Go to http://www.mandrakestore.com