On Thu, 27 Jan 2000, TAG wrote:
> HI ALL,
>

> ie: /usr/home/<user>/file needs to be converted with a program "convert"
> into /home/<user>/file2 - but I have over 3000 users??

Simple :)

--------------------------------------------
You get a list of all users by analyzing /etc/passwd:

cat    /etc/passwd    |    awk    -F:    '    {  print  $1  }    '    >    
/userlist.txt

( I added some extra spaces for readability )

                       this forwards each line of the password file to awk
 and then awk prints the first field of each line.
 -F:    is used to set the field separator to ":"
 The lines in /etc/password begin with "username:some more text"

-------------------------------------------
Similarly you can create a script that does the conversion:

cat    /etc/passwd    |    awk    -F:    '    {    print    "convert 
/usr/home/"$1"/file
    /home/"$1"/file2  }    '    >    /convert_script

now command:

        chmod +x /convert_script

        ./convert_script

and you get the conversion done. Remember the preceeding dot&slash.

If you need to make directories, then just add
          print "mkdir /home/"$1;

between the "{" and the "print". Do not forget the ";"


P L E A S E    R E A D    F U R T H E R !
-----------------------------------------------

Remember to remove users root, sys, bin, daemon etc. from
the script file before running it.

You can also automatically remove selected users from the file:
Modify the begining of the command:

cat /etc/passwd  |  grep  -f    /nonwanted    -v    |    awk    -F:    '    {
print    "convert /usr/home/"$1"/file      /home/"$1"/file2  }    '    >
/convert_script

        Here we use grep to filter out those usernames that we do not
        want to pass on to the awk program.  /nonwanted is a simple
        text file that contains excluded usernames one per row:

           root
           sys
           bin
           daemon
           ...


-------------------------------------------
This is a bit clumsy way as we create a 3000 row script file,
but at least you get the job done.

Maybe awk has an execute-command to replace this
create-an-ugly-scriptfile-method... Take a closer look
at awk manuals for fine tuning.

        I would recommend you to study both awk, sed and grep-commands.
        They are quite useful and flexible.


-----------------------------------------------
Ralf Christian Strandell
-----------------------------------------------

                .~.
                /V\            L    I    N    U    X
                // \      >Don't fear the penguin<
              /(    )\
              ^^-^^

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

Reply via email to