Shell script

brad brad at bradandkim.net
Wed Nov 12 15:18:15 CST 2003


OK, the first part is working and is correctly replacing the tab with a
pipe.  The second part is giving me trouble though.  When set up exactly
like you have it below I get the following when running the script:

[root at server2 root]# cat userlist| ./make_ftp
usage: adduser  [-u uid [-o]] [-g group] [-G group,...]
                [-d home] [-s shell] [-c comment] [-m [-k template]]
                [-f inactive] [-e expire ] [-p passwd] [-M] [-n] [-r] name
       adduser  -D [-g group] [-b base] [-s shell]
                [-f inactive] [-e expire ]
passwd: This option requires a user name.
usage: adduser  [-u uid [-o]] [-g group] [-G group,...]
                [-d home] [-s shell] [-c comment] [-m [-k template]]
                [-f inactive] [-e expire ] [-p passwd] [-M] [-n] [-r] name
       adduser  -D [-g group] [-b base] [-s shell]
                [-f inactive] [-e expire ]
passwd: This option requires a user name.

So I changed the make_ftp script to this:

#!/bin/bash

while read ALINE
do
IFS=|
echo $1
echo $2
done

and I get no output at all...just 3-4 blank lines.  It seems that it is not picking
up the variables correctly.   So that I can understand this, what is the IFS| ??

Thanks again everyone for the help.

Brad

Scott wrote:
> > > A two step process
> > > 
> > > Step #1 vi your FILE and then:
> > > 
> > > :/g/(TABHERE)/s//|/g
> > > :wq
> > > 
> > > This replaces the TAB with the | symbol.  It's just an old habit of mine that
> > > tends to make life easier for me sometimes.  At least it's consistant.
> > > 
> > > 
> > > 
> > > Step #2 Put in this shell script and run it with cat FILE|./SHELLSCRIPT
> > > 
> > > 
> > > #!/bin/sh
> > > while read ALINE
> > > do
> > > IFS=|
> > > /usr/sbin/useradd -c "$1 Account Whatever Comment Here" $1
> > > echo $2 | /usr/bin/passwd --stdin $1
> > > done
> > > 
> > > 
> > > You may have to tweak around with this a touch..  But it should do the job for
> > > you.  The script creates the account with default settings and then puts the
> > > password in for you using the passwd command.  The --stdin option to passwd is
> > > generally not documented well, if at all, but it's there in every distribution
> > > I've used.
> > > 
> > > scottm
> > > 




More information about the Kclug mailing list