Archive for May, 2007

ldapsearch syntax part three

Problem Looking for a given user, searching on 2 fields – first name and surname. Solution Here is an example of searching against 2 fields, effectively a logical AND. Example Searching on two fields and returning those fields, plus email.ldapsearch -x -v-D”cn=Manager,dc=demo,dc=net”-w secret-b’dc=demo,dc=net’ -s sub ‘(&(givenname=John)(sn=Doe))’givenname sn mail Reference Technorati Tags: ldapsearch syntax, openldap ldapsearch, [...]

ldapsearch syntax part two

Problem Looking for a given user, searching my first name. Solution ldapsearch can match on any field, within the LDAP record and perform wildcard matches. Example Here are some more examples:ldapsearch -L -x -v -D’cn=Manager,dc=demo,dc=net’ -w secret -b’dc=demo,dc=net’ -s sub ‘givenname=*’ givenname sn mailBasic LDAP syntax demo part2 Reference Technorati Tags: ldapsearch syntax, openldap ldapsearch, [...]

Solaris Network Tracing

Problem You are experiencing issues on the network, or a server process is playing up. Solution You need to trace network connection. In the example I provide examples using Solaris and Linux. AIX is similar to Linux in the is regard – either using tcpdump or iptrace. Example # network trace connection from hostname (solaris)snoop [...]

Perl TimeOut

Problem You have a script which runs too long and you want to time it out, after a given numberof seconds. Solution Useful bit of code to time-out a section of your Perl script, via the alarm function.See the example tab. Example #!/usr/bin/perleval {   local %SIG;   $SIG{ALRM}=     sub{ die "timeout reached, after 20 seconds!\n"; };   [...]

Linux Debugging strace

Problem You have a problem with a process, running some job on a Linux box and need to see some debug information.Sometimes the problem is a missing library, etc and you need to spot the missing dependency.Symptoms could be a binary runs fine on one system and fails on another. Solution On Linux use strace, [...]

Solaris Debugging

Problem You have a problem with a process, running some job on Solaris and need to see some debug information.Sometimes the problem is a missing library, etc and you need to spot the missing dependency.Symptoms could be a binary runs fine on one system and fails on another. Solution Run truss with the binary, to [...]

Java JNDI talk to LDAP

Problem You want to talk to LDAP from Java. Solution Java as well as Perl, PHP and plain old Shell have APIs to be able to talk to LDAP.The Java API is probably most complex one to use – I have provided some demos on how to use the others on this site.More will be [...]

ldapsearch syntax

Problem You want to perform an LDAP search Solution Starting this topic slowly, by giving practical tips on LDAP commands.Predominately LDAP has a couple of main commands: ldapsearch and ldapmodify. With openLDAP there is additionally ldapadd, with netscape this is just ldapmodify -a. Example ldapsearch [ -v ] -x -D’user’ -w’password’[ -h host -p port [...]

Perl WIN32 OLE – Outlook save text

Problem How to use Perl to connect to MS Outlook. Then descend through given folders and save items to disk, as text files. Solution I wrote this some time ago, to traverse predefined outlook mail folders, saving items with given subject to text.Requires WIN32:OLE perl module (which comes with activeperl by default).Hardcoded is the upload [...]

Perl libcurl demo

Problem You want to use libcurl, driven through Perl. Solution Beautiful for parse HTML and either extracted (screen scraping) content or performing actions based on results.See the examples tab for this simple script, demonstrating the libcurl API for Perl. Example #!/usr/bin/perl$url=”http://perl.coding-school.com/”; # set your url here$|++;use Curl::easy;# Init the curl sessionmy $curl= Curl::easy::init() or die [...]