Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Centos 7 getadsmtp.pl outputing blank

by gml_perl (Initiate)
on Jun 26, 2018 at 11:52 UTC ( #1217432=note: print w/replies, xml ) Need Help??


in reply to Re: Centos 7 getadsmtp.pl outputing blank
in thread Centos 7 getadsmtp.pl outputing blank

Perl version for the successful script is 0.4001 and where it is failing 0.65. I am using the same code on both servers and files named $valid are all created but empty. I am running the script from the command line there is no need for a cron we just run it manually each time we create new AD users. I am not so sure how to include Data::Dumper or print statements into the code.

  • Comment on Re^2: Centos 7 getadsmtp.pl outputing blank

Replies are listed 'Best First'.
Re^3: Centos 7 getadsmtp.pl outputing blank
by haukex (Archbishop) on Jun 30, 2018 at 19:43 UTC
    I am not so sure how to include Data::Dumper or print statements into the code.

    So I take it you're not a Perl programmer? I would suggest you read perlintro, it's not very long and it'll give you a good idea of Perl's syntax. Then, you can insert use Data::Dumper; above the line use Net::LDAP;, and at various places in the code, insert print Dumper($variable); or print Dumper(\@array); statements to get debug output, which you can compare across the two machines, or post here for feedback, if you like.

    Just for example, you might insert print Dumper($mail); inside the loop foreach my $mail ( $entry->get_value( "proxyAddresses" ) ) { ... } to see which, if any, mail addresses you are getting and whether they match the pattern /^(smtp|SMTP):/. You can repeat this for the other loops to see how many times those loops get executed, etc.

    Perl version for the successful script is 0.4001 and where it is failing 0.65.

    Have you had a chance to investigate poj's suggestion?

      My apologies I am not a perl programmer I come from the Linux side. 1. I now have the code as :-

      use Data::Dumper; use Net::LDAP; use Net::LDAP::Control::Paged; use Net::LDAP::Constant ( "LDAP_CONTROL_PAGED" );
      . . .
      while(1) { # Perform search my $mesg = $ldap->search( @args ); # Filtering results for proxyAddresses attributes foreach my $entry ( $mesg->entries ) { my $name = $entry->get_value( "cn" ); # LDAP Attributes are multi-valued, so we have to print each one. foreach my $mail ( $entry->get_value( "proxyAddresses" ) ) { # Test if the Line starts with one of the following lines: # proxyAddresses: [smtp|SMTP]: # and also discard this starting string, so that $mail is only th +e # address without any other characters... if ( $mail =~ s/^(smtp|SMTP)://gs ) { push(@valid, $mail." OK\n"); print Dumper($mail); } }
      I do not get any output

      Using Poj's Suggesstion:- I get this error message:- root@vm1000 getadscripts# ./getadsmtp_itbak1.pl Name "main::valid" used only once: possible typo at ./getadsmtp_itbak1.pl line 116, <DATA> line 755. $VAR1 = '/etc/postfix/ad_itdepartment';

        I have marked up your code with the 2 lines you need to comment out and 3 lines to add

        while(1) { # Perform search my $mesg = $ldap->search( @args ); # Filtering results for proxyAddresses attributes foreach my $entry ( $mesg->entries ) { my $name = $entry->get_value( "cn" ); # LDAP Attributes are multi-valued, so we have to print each one. foreach my $mail ( $entry->get_value( "proxyAddresses" ) ) { # Test if the Line starts with one of the following lines: # proxyAddresses: [smtp|SMTP]: # and also discard this starting string, so that $mail is only t +he # address without any other characters... if ( $mail =~ s/^(smtp|SMTP)://gs ) { push(@valid, $mail." OK\n"); } } } # Only continue on LDAP_SUCCESS $mesg->code and last; # Get cookie from paged control my($resp) = $mesg->control( LDAP_CONTROL_PAGED ) or last; #$cookie = $resp->cookie or last; # delete $cookie = $resp->cookie; # add last if (!defined($cookie) || !length($cookie)); # add # Set cookie in paged control $page->cookie($cookie); } #if ($cookie) { # delete if (defined($cookie) && length($cookie)) { # add # We had an abnormal exit, so let the server know we do not want any + more $page->cookie($cookie); $page->size(0); $ldap->search( @args ); # Also would be a good idea to die unhappily and inform OP at this p +oint die("LDAP query unsuccessful"); }
        poj

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1217432]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2023-03-24 18:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (61 votes). Check out past polls.

    Notices?