#! /usr/bin/perl use Net::LDAP; # ##### Start of configuration section # # $servername = "ldap.my-org.org"; $base = "ou=my-department,dc=my-org,dc=org"; # Change this to 1 if you configured the above items! $configured = 0; # Normally the settings below should not require changes. $subhosts = "ou=hosts"; $subethers = "ou=ethers"; $subng = "ou=netgroup"; $ochosts = "(objectClass=ipHost)"; $ocether = "(objectClass=ieee802Device)"; $ocng = "(objectClass=nisNetgroup)"; # # # ##### End of configuration section if($configured == 0) { print "ERROR: You *must* customize the configuration section before using itacldap!"; print "\n";; exit(1); } my $ldap; # Open LDAP connection $ldap = Net::LDAP->new( $servername ) or die "$@"; # Anonymous bind should be sufficient $mesg = $ldap->bind; if(open(OUTPUT, ">objects-to-delete")) { $mesg = $ldap->search( base => "$subhosts,$base", filter => "$ochosts", scope => 'sub', attrs => ['1.1'] ); foreach $entry ($mesg->entries) { print OUTPUT $entry->dn . "\n"; } $mesg = $ldap->search( base => "$subethers,$base", filter => "$ocether", scope => "sub", attrs => ['1.1'] ); foreach $entry ($mesg->entries) { print OUTPUT $entry->dn . "\n"; } $mesg = $ldap->search( base => "$subng,$base", filter => "$ocng", scope => "sub", attrs => ['1.1'] ); foreach $entry ($mesg->entries) { print OUTPUT $entry->dn . "\n"; } close(OUTPUT); } $mesg = $ldap->unbind;