1755744 Members
3259 Online
108837 Solutions
New Discussion юеВ

AWK , uid and NIS

 
SOLVED
Go to solution
Chern Jian Leaw
Regular Advisor

AWK , uid and NIS

HI

I have a text file of the following form, which is an output from "ls -l":

#cat fileList.txt
-rwx------ 1 chern oper 253 Jun 17 12:03 ChangeUID.csh
-rw-r--r-- 1 root oper 0 Jun 17 12:04 fileList.txt
-rwx------ 1 rlee oper 677 May 15 17:52 groups.bak
-rwx------ 1 wchan oper 775 May 14 14:27 groups.bak1

I had written a script to change the numeric ids of these users within this directory:

#cat ChangeUID.sh

foreach a (`cat fileList.txt`)
set uid=`id $3|awk '{print $1}'`
echo "uid = $uid"
switch ($uid)
case 0: chown 17190 $a
;;

case 1189:chown 1890 $a
;;

case 442: chown 3852 $a
;;

case 671: chown 1264 $a
;;
endsw
end

Users root, chern, rlee and wchan have their original uids as 0, 1189, 442, 671.

My question is:
1)Whenever this script is executed, the output is of the following :
uid = uid=0(root)
...... (infinitely)
It doesn't seem to change the old uids corresponding to the files in the firectory to the newly specified uid in the case statement.
Could anyone tell me how I should go about fixing this bug ?? and get the uids changed?

Also if the file-list contains different users needing to change their uids to some value, how can I do this in a more efficient manner?

2)Also, if the the /var/yp/src/passwd file were to be modified to include the new uids(in the NIS master), would this change be propogated to the NIS slave servers, and hence the NIS clients ?

Thanks.
5 REPLIES 5
harry d brown jr
Honored Contributor

Re: AWK , uid and NIS

Chern,

your "foreach" is yanking every single WORD, it's not grabbing each line as you would like.

Try making your script an "awk" script.

live free or die
harry
Live Free or Die
Leif Halvarsson_2
Honored Contributor

Re: AWK , uid and NIS

Hi

Instead of the foreach use a while loop

while read $a $b $c $d .....
do

#whatever you will do

done
john korterman
Honored Contributor
Solution

Re: AWK , uid and NIS

Hi Chern,

I tried to re-write yout script for Korn shell. The attached version will however only write the changes that it could perform: I find the script rather dangerous and leave it up to you to remove the comments in the case-structure. The ALLOWED_DIR should be set to the dir in which your files are.
You need to maintain the script yourself with regard to the user ids it should support. Hope it helps.

Regards John
it would be nice if you always got a second chance
sven verhaegen
Respected Contributor

Re: AWK , uid and NIS

Hi

About the NIS part , you could go and alter the data in the NIS map however I would not advise you to do so , NIS map are made by the YPMAKE command and that should be used , propagation of maps doesn't happen automatically if you don't use YPMAKE , you have to use YPPUSH or YPXFR to push or pull the changed maps to any slave servers , also yp read the map at startup so changes are not atomattic you could need to start YPSERv and YPBIND to make it work , if you ghave no idea on th estructure of the NIS maps themselfs I wish to refer you to the O'Reilly NFS & NIS manual (i forgot the ISBN number) it explains not only th emap structure but also the update procedure of maps withing a master/slave environment for NIS
...knowing one ignores a greath many things is the first step to wisdom...
harry d brown jr
Honored Contributor

Re: AWK , uid and NIS

Try this attached perl:

live free or die
harry
Live Free or Die