Sabiha has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I have tried to search the ldap via userid or nisnetgroup triple to find the netgroups the user is part of. The code is:
#!/usr/bin/perl -w use strict; use Net::LDAP; print "\nEnter the user id :"; my $uid = <STDIN>; $ldap = Net::LDAP->new("localhost"); $ldap->bind("ou=netgroup,ou=people"); $mesg = $ldap->search(filter=>"(nisNetgroupTriple=\(,$uid,\))", base=> +"ou=netgroup,ou=people",attrs=>['dn','cn']); @entries = $mesg->entries; foreach $entry (@entries){ $entry->dump;}
~ It does not give any output. Can anyone help?

Replies are listed 'Best First'.
Re: Searching Ldap by user id or nisNetgroupTriple
by NetWallah (Canon) on Feb 20, 2014 at 06:13 UTC
    This is just a wild guess - but perhaps
    chomp $uid;
    prior to using it for the ldap call may help.

    Please try it, and , for the benefit of others (and the opportunity to earn even more XP), report back whether or not it works.

            What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?
                  -Larry Wall, 1992

      Hi,chomp $uid is not working either.
        What was the value of $uid before and after chomp? DDumper it
        dd( $uid ); ... sub dd { use Data::Dumper; print Data::Dumper->new([@_])->Sortkeys(1) ->Indent(1)->Useqq(1)->Dump . "\n"; }
Re: Searching Ldap by user id or nisNetgroupTriple
by kcott (Archbishop) on Feb 20, 2014 at 13:45 UTC

    G'day Sabiha,

    "The code is: ... It does not give any output."

    Saving a verbatim copy of the code you posted as 'pm_1075535.pl', I get lots of output:

    $ pm_1075535.pl Global symbol "$ldap" requires explicit package name at ./pm_1075535.p +l line 6, <DATA> line 522. Global symbol "$ldap" requires explicit package name at ./pm_1075535.p +l line 7, <DATA> line 522. Global symbol "$mesg" requires explicit package name at ./pm_1075535.p +l line 8, <DATA> line 522. Global symbol "$ldap" requires explicit package name at ./pm_1075535.p +l line 8, <DATA> line 522. Global symbol "@entries" requires explicit package name at ./pm_107553 +5.pl line 9, <DATA> line 522. Global symbol "$mesg" requires explicit package name at ./pm_1075535.p +l line 9, <DATA> line 522. Global symbol "$entry" requires explicit package name at ./pm_1075535. +pl line 11, <DATA> line 522. Global symbol "@entries" requires explicit package name at ./pm_107553 +5.pl line 11, <DATA> line 522. Global symbol "$entry" requires explicit package name at ./pm_1075535. +pl line 13, <DATA> line 522. Execution of ./pm_1075535.pl aborted due to compilation errors. $

    If you're only looking at stdout output, the reason that you don't see any output is because your code doesn't compile and, therefore, is not run:

    $ pm_1075535.pl 2> /dev/null $

    Assuming you're not actually throwing away stderr output, please post code that compiles and all output it produces.

    We cannot help you with your code if you do not post the actual code you're running!

    -- Ken