LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-15-2008, 07:08 AM   #1
felosa_vb
LQ Newbie
 
Registered: Jan 2008
Posts: 1

Rep: Reputation: 0
Unhappy script ,ldapsearch,sqlloader


Hello has all,
I seek has to make a total script which enables me to extract from the data of a Ldap directory, put them in the form of fichier.ldif, then transform it into file.csv and after charging my data in my basic table by using the sqlloader, but I do'nt know too much how to make on the level syntax!

Code:
ldapsearch ....
awk -f .... file.ldif > file.csv
sqlloader....

can you help me to solve this problem please, thank you in advance for your assistance
 
Old 01-16-2008, 07:48 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Hi,

And welcome to LQ!

I don't know the complexity of your schema (many multi-value attributes?), and haven't
got a clue what sqlloader is or does, but if the task at hand is simple enough I can
throw you a script I've written here for a similar purpose.

Code:
# Author:   tink
# purpose:  make a CSV file to feed into Oracle from an LDIF file as
#           produced from an ldapsearch
# 

BEGIN{
# Set-up an array with the names that ORA requires out of the LDIF
# the o[1-4] fields are dummys which we will export empty
  list[1]="cn"
  list[2]="givenname"
  list[3]="o1"
  list[4]="sn"
  list[5]="attribute1"
  list[6]="mail"
  list[7]="o2"
  list[8]="attribute2"
  list[9]="attribute3"
  list[10]="attribute4"
  list[11]="attribute5"
  list[12]="o3"
  list[13]="attribute6"
  list[14]="attribute7"
  list[15]="o4"
  list[16]="role"
  list[17]="attribute8"
  list[18]="attribute9"
  list[19]="attribute10"
# Tell awk to ignore case in pattern matching, just for good measure
  IGNORECASE=1
  RS="\n\n"
  FS="\n"
  ORS="\n\n"
  OFS="\n"
}
{
  if( $0 ~ /objectClass: Person/ ){
  # the fields get parsed and assigned to an array with the "Field name"
  # as the index (see the field names above).  Basically something like
  # "sn=Jones" gets assigned to res["sn"]=Jones
    for( i = 1; i <= NF; i++ ){
      for( l in list ){
        if( $i ~ "^"strip( list[l]) ){
          res[strip( list[l])]= strip( rparse( $i ))
        }
      }
    }
  # print the fields of the array mentioned before in order
    for( j=1;j<=18;j++ ){
      printf( "\"%s\",", res[list[j]])
    }
    printf "\"%s\"\n",res[list[19]]
  }
}

# get the "name" of a field
function lparse( var ){
  return gensub( /([^:]+):.+/, "\\1", "g",var)
}

# get the "value" of a field
function rparse( var ){
  return gensub( /[^:]+:(.+)/, "\\1", "g",var)
}

# remove leading and trailing whitespace
function strip( var ){
  return gensub( /^ *([^ ]+)/, "\\1", "1", gensub( /([^ ]+) *$/, "\\1", "1", var  ) )
}

For reasons of anonymity I renamed attributes that are specific to my field of work
with attributeX, but you may get the idea. Note that in the code the loops match the
number of attributes we defined for the array above.



Cheers,
Tink

Last edited by Tinkster; 01-16-2008 at 08:14 PM. Reason: spello (as opposed to typo)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ldapsearch | ldapmodify eantoranz Linux - Software 1 01-28-2013 09:33 PM
ldapsearch cmontr Programming 4 11-15-2007 04:19 PM
strange ldapsearch error PhillipHuang Linux - General 0 09-19-2006 12:27 AM
ldapsearch with incomplete base returns no results superhausi Linux - Software 0 10-25-2005 03:23 AM
OpenLDAP, ldapsearch: how to list all attributes Hko Linux - Networking 0 08-15-2004 10:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration