13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 2 ■ CENTRALIZING YOUR NETWORK: KERBEROS, LDAP, AND NFS01 #!/usr/bin/perl -w0203 use strict;04 use Net::LDAPS;0506 die "Usage: showdisks machinename\n"unless (@ARGV == 1);0708 # Get & set values09 my ($search) = @ARGV;10 my $server = "ldaps://ldap.example.com";11 my $cert = "/etc/ldap/servercert.pem";12 my $base = "dc=example,dc=com";1314 my $ldap = Net::LDAPS->new( $server,15 verify => 'optional',16 cafile => $cert ) or die $@;17 my $mesg = $ldap->bind;1819 my $filter = "(automountInformation=*$search*)";2021 $mesg = $ldap->search( base => $base,22 filter => $filter,23 attr => ['cn', 'automountInformation'],24 );2526 $mesg->code && die $mesg->error;2728 my @entries = $mesg->sorted('cn');2930 foreach my $entry ( @entries ) {31 my $location = $entry->get_value( 'automountInformation' );32 my $name = $entry->get_value( 'cn' );3334 if ($cn) {35 my ($options, $path)= split $automount;36 print "$name : $path ($options) \n";37 }38 }3940 $mesg = $ldap->unbind;See recipe 2-9 for an in-depth discussion of the Net::LDAPS or Net::LDAP Perl modules (see line 04)and for how to use them to add an entry. Recipe 2-10 tackles how to modify and delete entries. Line 06checks that there’s only one argument (the machine name to look for) being passed in. Lines 08–12 setup your values, including the search value $search (the machine name that was passed in from thecommand line). Lines 14–17 connect to the LDAP server (you can if you prefer use Net::LDAP; seerecipe 2-9).56Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!