Newbie AWK Question 
Author Message
 Newbie AWK Question

Hi all,

I am trying to write a script that will create multiple users.  The
users are being taken from the /etc/passwd file from the old system and
need to be created on the new system.

I have the /etc/passwd file cleaned up to give me the userid:full-name
fields to work with.  Rather than using a loop to read each line, is
there a way to use AWK? [something like the following]:

grep filename | awk -F: `{userid=$1 username=$2}` \
mkuser gecos=$username shell=/usr/bin/csh grp=mygrp $userid

This doesn't work, but I'll bet you guru's know what I'm trying to do
and can figure out how to accomplish it, huh?  Is there a way to exec
the mkuser within awk to have access to those variables?

Thanks in Advance...

Karen.



Fri, 09 Jul 1999 03:00:00 GMT  
 Newbie AWK Question

Quote:

>Hi all,

>I am trying to write a script that will create multiple users.  The
>users are being taken from the /etc/passwd file from the old system and
>need to be created on the new system.

>I have the /etc/passwd file cleaned up to give me the userid:full-name
>fields to work with.  Rather than using a loop to read each line, is
>there a way to use AWK? [something like the following]:

>grep filename | awk -F: `{userid=$1 username=$2}` \
>mkuser gecos=$username shell=/usr/bin/csh grp=mygrp $userid

>This doesn't work, but I'll bet you guru's know what I'm trying to do
>and can figure out how to accomplish it, huh?  Is there a way to exec
>the mkuser within awk to have access to those variables?

It could be done within awk, but you could also do it with a shell script:
#!/bin/sh
IFS=":"
while read userid username junk
do; mkuser gecos=$username shell=/usr/bin/csh grp=mygrp $userid
done <filename

You could also use the shell field from the old passwd file unless you
have some reason for forcing everyone to use csh (or maybe that's what
they were all using anyway).

Grep isn't needed unless you are searching for some string which you
omitted above; in that case you could do:

grep 'string' filename | (
IFS=":"
while read userid username junk
do; mkuser gecos=$username shell=/usr/bin/csh grp=mygrp $userid
done)

--
Bill Marcum    bmarcum at iglou dot com
In the computer lab, Nyarlathotep turned back to the terminal.  He hit the
Key With No Name Or ASCII Equivalent, and vanished.



Sat, 10 Jul 1999 03:00:00 GMT  
 Newbie AWK Question

Thank You Everyone!!  Your help is GREATLY appreciated!

Karen.



Sat, 10 Jul 1999 03:00:00 GMT  
 Newbie AWK Question


writes:

-Hi all,
-
-I am trying to write a script that will create multiple users.  The
-users are being taken from the /etc/passwd file from the old system and
-need to be created on the new system.
-
-I have the /etc/passwd file cleaned up to give me the userid:full-name
This is ominous.
-fields to work with.  Rather than using a loop to read each line, is
-there a way to use AWK?
[ deleted ]
-Thanks in Advance...
-
-Karen.

Untested:

awk '
{
        userid=$1; username=$2 # If thats the way filename is formatted
        system("/usr/path.../mkuser " userid " " username) # I dont
                                        # know the way to call mkuser

Quote:
}

' filename

Martin Cohen, AMSAA-North, Custom House Rm 800
Philadelphia, PA 19106-2976 (215) 597-8377 DSN 444-3808



Sat, 10 Jul 1999 03:00:00 GMT  
 Newbie AWK Question

: I am trying to write a script that will create multiple users.  The
: users are being taken from the /etc/passwd file from the old system and
: need to be created on the new system.

: I have the /etc/passwd file cleaned up to give me the userid:full-name
: fields to work with.  Rather than using a loop to read each line, is
: there a way to use AWK? [something like the following]:

: grep filename | awk -F: `{userid=$1 username=$2}` \
: mkuser gecos=$username shell=/usr/bin/csh grp=mygrp $userid

Try something like the below.  I'm not sure what the grep
above is for, but you can use the awk pattern matching facility
equally easily.  Have awk print out the command line you need
to run your mkuser script (assuming it won't take stdin):

awk -F: '{print "mkuser gecos=",$userame,
        "shell=",$priorshell, etc}' oldpwfile | /bin/sh

mike

--

Any opinions expressed are mine only, and not necessarily
those of any other entity.  They may not even be mine.



Sat, 10 Jul 1999 03:00:00 GMT  
 Newbie AWK Question

Quote:

>I have the /etc/passwd file cleaned up to give me the userid:full-name
>fields to work with.  Rather than using a loop to read each line, is
>there a way to use AWK? [something like the following]:
>grep filename | awk -F: `{userid=$1 username=$2}` \
>mkuser gecos=$username shell=/usr/bin/csh grp=mygrp $userid

I would suggest to write the command in a file and execute it:
awk -F: `
{
        printf("mkuser gecos=%s shell=/usr/bin/csh grp=mygrp %s\n",$1,$2)
Quote:
}

` filename > result.ksh
ksh result.ksh

Hope this helps,
Patrice.

----------------------------------------------------------------------

|  #include <disclaimer.h>  | V-mail : (+33) [0]4 92 29 39 49 + 3902 |
----------------------------------------------------------------------



Sat, 10 Jul 1999 03:00:00 GMT  
 Newbie AWK Question

Two ways to deal with running commands from within awk script

1.  awk -f script.awk < psswd.txt | sh
2.  use nawk  which supports  system(expression)  call.
--
----------------------------------------------

MCSE & Certified Solaris System Administrator.



Sun, 11 Jul 1999 03:00:00 GMT  
 Newbie AWK Question

Quote:

>I am trying to write a script that will create multiple users.  The
>users are being taken from the /etc/passwd file from the old system and
>need to be created on the new system.
>I have the /etc/passwd file cleaned up to give me the userid:full-name
>fields to work with.  Rather than using a loop to read each line, is
>there a way to use AWK? [something like the following]:
>grep filename | awk -F: `{userid=$1 username=$2}` \
>mkuser gecos=$username shell=/usr/bin/csh grp=mygrp $userid

What I think you want to do can be done with this
awk -F: '{print "mkuser gecos=" $2 " shell=/usr/bin/csh grp=mygrp " $1 }' /etc/passwd

The output can be written to a file for subsequent 'execution'

Hope this helps...
Mark
--
Mark Katz
ISPC, London - Innovation in data-delivery tools
Tel: (44) 181-455 4665, Fax (44) 181-458 9554
** Visit our website on http://www.efiche.com/efiche **



Mon, 12 Jul 1999 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. A Newbie AWK question

2. newbie awk question

3. AWK newbie is looking for a AWK help with his 1st program

4. Newbie awk (sed??) question, regular expressions

5. Newbie question -- to make an awk program act on a collection of files

6. AWK for DOS - NewBie Question

7. awk Newbie question

8. Newbie question: how to learn (N)AWK

9. Newbie question on using System() and Awk

10. AWK Newbie Question

11. newbie question on Tcl with awk

12. Newbie Question (Was: Newbie Question...)

 

 
Powered by phpBB® Forum Software