Good idea to use awk since it already parses on whitespace.
Here's a safer approach: use awk to create a shell script containing
lines of the form:
useradd 'login' && echo 'password' | passwd --stdin
useradd 'login2' && echo 'password2' | passwd --stdin
something like this:
awk '{printf "useradd \"%s\" && echo \"%s\" | passwd --stdin
\"%s\"\n", $1, $2, $1}' inputfile.txt > output_script.sh
you can then make sure that output_script.sh is correct before running it.
On 5/26/06, seekuel <[EMAIL PROTECTED]> wrote:
Sir this is the script edited:
-----------
#!/bin/bash
exec < users.txt
while read LINE; do
IFS=" "; set -- $(echo $LINE)
MyUserName=$1
MyPassword=$2
MyFullName=$3
useradd "${MyUserName}" -c "${MyFullName}"
echo "${MyPassword}" | passwd "${MyUserName}" --stdin
done
------------
And this is the result:
--------------
useradd: invalid user name '2710050 waombao WILBERT_A_OMBAO'
passwd: Unknown user name '2710050 waombao WILBERT_A_OMBAO'.
useradd: invalid user name '2710034 esrosel ERIC_S_ROSEL'
passwd: Unknown user name '2710034 esrosel ERIC_S_ROSEL'.
useradd: invalid user name '2710040 pbbelleza PATRICK_B_BELLEZA'
passwd: The user name supplied is too long.
----------------
This are in users.txt:
---------------
password username fullname
-------------- -------------- -------------
2710050 waombao WILBERT_A_OMBAO
2710034 esrosel ERIC_S_ROSEL
2710040 pbbelleza PATRICK_B_BELLEZA
----------------
I'm not sure if I did the right step.
But from the result I think the script did not brake the line "<space> "
and assign it to a separate variable but instead it parse the whole line as
1 variable.
Sory for asking this: Is there still hope for the script? :)
Thanks and more power
On 5/26/06, Dark Knight <[EMAIL PROTECTED]> wrote:
>
> yes good suggestion, thanks for the clarification.
>
>
>
>
> On 5/26/06, Lawrence Guirre - GMAIL < [EMAIL PROTECTED] > wrote:
> >
> >
> >
> > If the fullname contained spaces, this would not work since $3 would get
> > only the first non-whitespace word after the username. I'd suggest you
change
> > the format of the text file with another field separator like ':'
> >
> >
> > ----- Original Message -----
> > From: Dark Knight
> > To: Philippine Linux Users' Group (PLUG) Technical Discussion List
> > Sent: Thursday, May 25, 2006 11:35 PM
> > Subject: Re: [plug] useradd and passwd script
> >
> > but it wont work if you have multiple lines of account/s. you have to
reiterate the file with something like:
> >
> > #!/bin/bash
> >
> > exec < password_file
> >
> > while read LINE; do
> > IFS=" "; set -- $(echo $LINE)
> >
> > MyUserName=$1
> >
> > MyPassword=$2
> > MyFullName=$3
> > useradd "${MyUserName}" -c "${MyFullName}"
> >
> > echo "${MyPassword}" | passwd "${MyUserName}" --stdin
> >
> > done
> >
> > <End Script>
> >
> >
> > On 5/26/06, Gabriel Briones <[EMAIL PROTECTED]> wrote:
> > >
> > > OOppsss my bad, may error sa script :-)
> > >
> > > here's the corrected script
> > >
> > >
> > > <Begin Script>
> > >
> > > #!/bin/bash
> > >
> > > MyFile=password_file
> > >
> > > MyUserName=`cat "${MyFile}" | awk '{print $2}'`
> > >
> > > MyPassword=`grep ${MyUserName} ${MyFile} | awk '{print $1}'`
> > > MyFullName=`grep ${MyUserName} ${MyFile} | awk '{print $3}'`
> > >
> > >
> > > useradd "${MyUserName}" -c "${MyFullName}"
> > >
> > > echo "${MyPassword}" | passwd "${MyUserName}" --stdin
> > >
> > > <End Script>
> > >
> > >
> > >
> > > On 5/26/06, Gabriel Briones < [EMAIL PROTECTED]> wrote:
> > > >
> > > > Hi,
> > > >
> > > > try this simple script
> > > >
> > > > <Begin Script>
> > > >
> > > > #!/bin/bash
> > > >
> > > > MyFile=password_file
> > > >
> > > > MyUserName=`cat "${MyFile}" | awk '{print $2}'`
> > > > MyPassword=`grep ${MyUserName} | awk '{print $1}'`
> > > > MyFullName=`grep ${MyUserName} | awk '{print $3}'`
> > > >
> > > > useradd "${MyUserName}" -c "${MyFullName}"
> > > >
> > > > echo "${MyPassword}" | passwd "${MyUserName}" --stdin
> > > >
> > > > <End Script>
> > > >
> > > > just replace password_file with your actual file
> > > >
> > > >
> > > > Hope this helps
> > > >
> > > > regards,
> > > > -jon-
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > On 5/26/06, seekuel < [EMAIL PROTECTED] > wrote:
> > > >
> > > > >
> > > > > Hi Sirs,
> > > > >
> > > > > This is the format of the txt document:
> > > > > -----
> > > > > password username fullname
> > > > > -----
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > >
> > > > Keyboard error, press F1 to continue
> > >
> > >
> > >
> > > --
> > >
> > > Keyboard error, press F1 to continue
> > > _________________________________________________
> > > Philippine Linux Users' Group (PLUG) Mailing List
> > > [email protected] (#PLUG @ irc.free.net.ph)
> > > Read the Guidelines: http://linux.org.ph/lists
> > > Searchable Archives: http://archives.free.net.ph
> > >
> > >
> >
> >
> >
> >
> > ________________________________
> >
> >
> > _________________________________________________
> > Philippine Linux Users' Group (PLUG) Mailing List
> > [email protected] (#PLUG @ irc.free.net.ph)
> > Read the Guidelines: http://linux.org.ph/lists
> > Searchable Archives: http://archives.free.net.ph
> >
> >
> >
> > _________________________________________________
> > Philippine Linux Users' Group (PLUG) Mailing List
> > [email protected] (#PLUG @ irc.free.net.ph)
> > Read the Guidelines: http://linux.org.ph/lists
> > Searchable Archives: http://archives.free.net.ph
> >
> >
>
>
> _________________________________________________
> Philippine Linux Users' Group (PLUG) Mailing List
> [email protected] (#PLUG @ irc.free.net.ph)
> Read the Guidelines: http://linux.org.ph/lists
> Searchable Archives: http://archives.free.net.ph
>
>
_________________________________________________
Philippine Linux Users' Group (PLUG) Mailing List
[email protected] (#PLUG @ irc.free.net.ph)
Read the Guidelines: http://linux.org.ph/lists
Searchable Archives: http://archives.free.net.ph
_________________________________________________
Philippine Linux Users' Group (PLUG) Mailing List
[email protected] (#PLUG @ irc.free.net.ph)
Read the Guidelines: http://linux.org.ph/lists
Searchable Archives: http://archives.free.net.ph