#passwd_to_names.nawk #04-MAR-1997, David Mathog, Biology Division, Caltech # reformat a password file into a database entry for the name space system # # Example (POSIX compatible system): awk -f passwd_to_names.nawk -v group=cco -v format=database /etc/passwd >out.lis # Example (Others): nawk -f passwd_to_names.nawk group=cco format=database < /etc/passwd >out.lis # # afterwards, you must do global search and replaces to replace OPERATOR,DATE # with the appropriate values. # # -v actions: # group=cco # When present on the command line, then this script will do some Status # # replacements by mapping the group # fields as follows: # # 102="Staff" # 103="Faculty" # 104="Graduate Student" # 105="Undergraduate Student" # # anything else becomes "Unclassified". These are the field usages # at CCO, but probably nowhere else, so leave off the -v group=cco # on other machines # # format=database # Writes record in Database format (With the S:,L:, etc.) Leave this # off and it writes it in Web submission format, so that it can # go through the multiple submission web page. # # All commas encountered in input fields are converted to spaces # All (whatever) encountered in input fields are deleted before creating # long account names # # BEGIN{FS=":"} # # main part # { #$0 is short, $4 is status, $5 is username short = $1 status = $4 username = $5 division = "Unclassified" # # get rid of all commas, replace with spaces # n=gsub(","," ",username) # # compress any series of spaces to one space # remove any any terminal spaces # while(gsub(" "," ",username)); sub("^ ","",username) sub(" $","",username) long = username # # get rid of any (whatever) in long account, then compress spaces # (some may have crept back in) # while(gsub("[(].+[)]","",long)); while(gsub(" "," ",long)); sub("^ ","",long) sub(" $","",long) # #if the user's name is too long to be a long account name #hack it up into first, middle, and last parts, and then #try to reduce the size by first leaving out the middle, then #truncating the first to an initial. If that fails, use SHORT # if(length(long) > 20) { pieces=split(long,array," ") first=array[1] last=array[pieces] if(pieces == 1)first = ""; if(length(first)+length(last)+1 > 20) { # # rats, first plus last is too big, try truncating first to # an initial # first = substr(first,1,1) first = sprintf("%s.",first) if(length(first)+length(last)+2 > 20) { # # still too long, give up and use short for long # long = short } else { long = sprintf("%s %s",first,last) } } else { long = sprintf("%s %s",first,last) } } # # if we're doing cco type replacements, do them now # hold = status if(group == "cco") { if(status == 102)status="Staff"; if(status == 103)status="Faculty"; if(status == 104)status="Graduate Student"; if(status == 105)status="Undergraduate Student"; } if(hold == status)status = "Unclassified"; # # now output the line # if(format == "database") { printf("S:%s,L:%s,N:%s,V:%s,T:%s,O:Operator,D:Date\n",short,long,username,division,status); } else { printf("%s,%s,%s,%s,%s\n",short,long,username,division,status); } }