Code Comments
Programming Forum and web based access to our favorite programming groups.Hi all,
I'm having trouble combining a ksh and awk script for editing the
passwd file.
I want to lookup a user in our corporate directory through a
ldapsearch, and if the user doesn't exist he/she will get a # in front
of their userid in passwd, thus disabling their userid for future
purge.
If someone has a solution to this problem i would be really grateful.
The small script uses arrays in awk to place and keep order of which
line and user I'm processing. Here's the script. Thankful for any help.
########################################
###################################=
########################################
###############
# This Script will check for a user in vcd.corporation.net thru a
ldapsearch if the user doesn't exist in the Corporate Directory
the userid will get a # in front of it in passwd
#! /bin/ksh
nawk 'BEGIN {FS =3D ":"} # Setting the FS =3D Field Separator for awk
{
for (i =3D 1; i <=3D NR; ++i) #This is where I keep track of which
linenumber I'm at in the passwd file
{
NR =3D=3D i
# print $1 # unneccesary line perhaps, since awk already knows
what value $1 is
$1 =3D currentuser # setting value of $1 for each NR to
currentuser
facts=3D$(/bin/ldapsearch -h vcd.corporation.net -B
uid=3Dcurrentuser fullName l departmentNumber mail telephoneNumber
Organisa
tion ou | tr "\303\205\266\251\244\245\226\204" "\000=C5=F6=E9=E4=E5=D6=C4")
# this is where the ldapsearch is being done
fullnAme=3D$(print "$FACTS" | grep fullName=3D | awk -F"=3D" '{print
$2}') # the
fullName variable is set
if
[[ -z $fullnAme ]]; then
userreplacement=3D`echo $currentuser |awk '{print"#"$1}'`
#this is where
the # is being made in front of the userid because
it doesnt exist in the Corporate Directory
perl -pi -e 's/$currentuser/$userreplacement/' $HOME/uid/passw
# replace USER
that doesnt exist in vcd with #USER in pass
wd, observe this is a local passwd copy
fi
}
}' $HOME/uid/passw
########################################
###################################=
########################################
##############
Post Follow-up to this message<warezcrc@hotmail.com> wrote in message news:1102090807.028306.53640@z14g2000cwz.googlegrou ps.com... > Hi all, > I'm having trouble combining a ksh and awk script for editing the > passwd file. > I want to lookup a user in our corporate directory through a > ldapsearch, and if the user doesn't exist he/she will get a # in front > of their userid in passwd, thus disabling their userid for future > purge. Rather than directly altering the passwd file, since if anything goes wrong you might render your server unusable, use a command like "passwd" or "usermod" to lock or disable the account. A newsgroup devoted to your operating system may have more details, or comp.lang.shell for help with scripting. Essentially, for each user, if ldapsearch fails: passwd -l -- John.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.