ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello guys, I would appreciate if someone can help me for this task:
I have a large txt file that contains lots of user ids in different format. I need to run this against a database output ldif file and print to a file whether they exist or not. And if they exist then I need to print their information from the ldif file. I appreciate in advance if anyone can assist.
I'd go with building a hash to store the ldif info, but each entry would only contain the uid, dn, cquestion, and userstatus, keyed on uid.
Then read through the user file in a loop and do
need more clues,
the users are each on a line, like 123thebestfather, 1superman1 etc?
is the uid in idfile uid:? (MYFILE1)
a more complete ldif file would be something to work with.
do we get paid
Hi - Yes uid's are like you said but there are many of them in a text file. The questions is that that text file contains uid's are in the ldif file or not... For exaple, if one of the uid is found, then print the values such as dn. if not found, print elsewhere etc. Thank you very much.
Here's a quick and dirty go,
not fully robust
multiple fields like objectclass:
will get mashed together in the wash
does regex match (if you prefer), and will match multiple names on the command line
Code:
#!/usr/bin/perl -s
my $db_name = "database"; # change this bit
local $/ = ""; # paragraph mode
local $\ = "\n"; # print terminator
open DATABASE, "<$db_name" or die "cannot open $db_name:$!\n";
@ARGV or die "search for who?\n";;
while (<DATABASE>) {
$debug and print "=" x 30, "\n"; # -debug switch
@L = split /(\w+):\s*/; # split on colon fields
shift @L; # first field is null, lose it
chomp @L;
$debug and print "@L";
$H = { @L }; # convert to a hash
foreach $uid (@ARGV) {
# UNCOMMENT TO ALLOW AN EXACT MATCH ONLY
# next unless $H->{uid} eq $uid;
# this is a regex match (not shell patterns)
next unless $H->{uid} =+ m/$uid/;
# choose your fields
print "=" x 30;
print $H->{dn};
print $H->{cquestion};
print $H->{userstatus};
}
}
Code:
./1.pl ROG test3
==============================
uid=ROGER,ou=someconsumer,o=abc.com
what is your father's name?
==============================
uid=test3,ou=someconsumer,o=abc.com
In what City did/do your parents live?
How could I store txt and ldif in a dbm file ? The need is to look for uids given in txt in the ldif file, then if they exist print the info like dn etc...
I tried modifying the line "my $db_name = "test.txt"; # change this bit" however I couldnt get it running yet. I have 2 files whioh one contains uid's list, and the other is the ldif file. Would you please tell me where to modify this perl script in order to get it running? Thank you very much.
Actually BB, I meant read the ldif file line by line as normal, and (as I said) ONLY store the relevant fields, which would cut down the amt of data dramatically. Even a 15 GB file would prob shrink enough. Could always use a Tied hash if it's too big.
BTW:
next unless $H->{uid} =+ m/$uid/;
shouldn't that be
next unless $H->{uid} =~ m/$uid/;
you did say regex
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.