Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

editing the passwd file
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
 ########################################
###################################=
 ########################################
##############


Report this thread to moderator Post Follow-up to this message
Old Post
warezcrc@hotmail.com
12-03-04 08:56 PM


Re: editing the passwd file
<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.



Report this thread to moderator Post Follow-up to this message
Old Post
John L
12-04-04 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:25 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.