Shell script

Charles Steinkuehler charles at steinkuehler.net
Wed Nov 12 00:15:18 CST 2003


brad wrote:
> Thanks for the help...that is exactly what I am wanting to do, but it is
> not working for me.  When I go into vi and type :/g/> 
> it won't let me hit tab then...I just get the beep that I am doing
> something wrong.  
> 
> Thoughts?

Likely due to some typo's...additional comments inline.

> Scott wrote:
> 
>> A two step process
>> 
>> Step #1 vi your FILE and then:
>> 
>> :/g/(TABHERE)/s//|/g
>> :wq

Try this instead:
:%s/<tab>/|/g
:wq

The tab above is in the wrong location (where the command should be), 
which is likely why vi is torqued.

>> 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=|

You need at least a set command here, or the following parameter 
expansions won't be as expected:
set -- $ALINE

>> /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.

 From "man passwd" on RHEL-3:
<quote>
--stdin
     This option is used to indicate that passwd should read the  new
     password from standard input, which can be a pipe.
</quote>

-- 
Charles Steinkuehler
charles at steinkuehler.net




More information about the Kclug mailing list