Sponsored Content
Top Forums Shell Programming and Scripting LDAP data in CSV format - Part II Post 302974349 by ItalianTripod on Saturday 28th of May 2016 06:26:57 PM
Old 05-28-2016
LDAP data in CSV format in KSH

Here's a ksh script accomplishing the same end result with the exception of including all members in each group, instead of only the last member. The script also archives the csv file before clearing the contents. Is this what you are looking for?
Smilie

Code:
#!/usr/bin/ksh93

if [[ $# -eq 0 ]];then
  print "Invalid Usage: Argument expected."
  exit 1
fi

LDAP_CSV_FILE="./SAM_GROUPS.ldif.csv"
LDIF_FILE="./"$@

if [[ ! -f ${LDIF_FILE} ]] ;
then
  print "SAM ldif file called" $@ "does not exist."
  exit 1
fi

if [[ -f ${LDAP_CSV_FILE} ]] ;
then
  cp ${LDAP_CSV_FILE} ${LDAP_CSV_FILE}"."`date +%Y%m%d`
 if [ $? == 0 ]; then
    cat /dev/null > ${LDAP_CSV_FILE}
 fi
fi

 while read LINE
do
if [[ ${LINE} == cn=* ]] && [[ ${LINE} != *","* ]] ;
then
  GROUP=${LINE:3}
fi

if [[ ${LINE} == uniquemember=* ]] ;
then
  MEMBER='"'${LINE:13}'"'
fi

if [[ ${LINE} == *uniquemember=* ]] ;
then
  echo ${GROUP}","${MEMBER} >> ${LDAP_CSV_FILE}
fi

done < ${LDIF_FILE}

This User Gave Thanks to ItalianTripod For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to format a .CSV data

Hi There I needed to write a Unix shell script which will pick up the data from a .CSV file and reformat it as per the requirement and write it to another .CSV file. Currently I am in the proess of Data Import to "Remedy System" (A one kind of incident mangement Application) and this... (8 Replies)
Discussion started by: Uday1982
8 Replies

2. UNIX for Advanced & Expert Users

shell script to format .CSV data

Hi all, I have written a shell script to search a specified directory (e.g. /home/user) for a list of specific words (shown as ${TMPDIR}/wordlist below). The script works well enough, but I was wondering if there was a way to display the line number that the word is found on? Thanks! cat... (1 Reply)
Discussion started by: tmcmurtr
1 Replies

3. Shell Programming and Scripting

Retaining the Unix CSV format in Excel format while exporting

Hi All, I have created a Unix Shell script whch creates a *.csv file and export it to Excel. The problem i am facing is that Users wants one of the AMOUNT field in comma separted values. Example : if the Amount has the value as 3000000 User wants to be in 3,000,000 format. This Amount format... (2 Replies)
Discussion started by: rawat_me01
2 Replies

4. Shell Programming and Scripting

Conversion of xhtml data into csv format using dump utility

Hi Unix Gurus, I tried to convert the attached xhtml table content into csv file using unix shell script (lynx -dump filename) and got the below results: Title ID Owner Priority Estimate Project Change Date Changed By Complexity Create Date Created By Detail Estimate Total De tail... (6 Replies)
Discussion started by: bi.infa
6 Replies

5. Shell Programming and Scripting

CSV data format manipulation

Hi There I need a script which will pick up the data from a .CSV file and reformat it as per the requirement and write it to another .CSV file. I am using an application that will only take data in a particular format and need something that will convert without manual intervention. The... (4 Replies)
Discussion started by: rbggbr16
4 Replies

6. Shell Programming and Scripting

LDAP data in CSV format

Hi all, I am new here, please don't eat me alive.. I am trying to find a good community to learn and participate in unix / linux discussions to help me improve in my current job. That being said, I have a problem which I didn't expect to challenge me, but I can't seem to find a viable... (8 Replies)
Discussion started by: tfm217
8 Replies

7. Shell Programming and Scripting

Convert csv data to html format

I am new to html and need to convert the attached csv file data to html format ; running into issues. please assist. #!/bin/ksh echo "<html>" ; echo "<head><style> table {border-collapse: collapse;} table, td, th {border: 1px solid black;} </style></head>" echo "<title> REPORT </title>" echo... (0 Replies)
Discussion started by: archana25
0 Replies

8. Shell Programming and Scripting

Can we filter the below log data into CSV format?

HI , I m looking for help here!!! Can we filter the below log data into CSV format ? timestamp INFO <text > - Some text Drive .. Need a format of separate field such as 1 2 3 4 ... (2 Replies)
Discussion started by: MohSalNiz
2 Replies

9. UNIX for Beginners Questions & Answers

Log file data into CSV format

I m looking for help here!!! Can we filter the below log data into CSV format ? 1 2 3 4 5 6 7 8 timestamp INFO <text > - Some text (1 Reply)
Discussion started by: MohSalNiz
1 Replies
Mixin::Linewise::Readers(3)				User Contributed Perl Documentation			       Mixin::Linewise::Readers(3)

NAME
Mixin::Linewise::Readers - get linewise readers for strings and filenames VERSION
version 0.004 SYNOPSIS
package Your::Pkg; use Mixin::Linewise::Readers -readers; sub read_handle { my ($self, $handle) = @_; LINE: while (my $line = $handle->getline) { next LINE if $line =~ /^#/; print "non-comment: $line"; } } Then: use Your::Pkg; Your::Pkg->read_file($filename); Your::Pkg->read_string($string); Your::Pkg->read_handle($fh); EXPORTS
"read_file" and "read_string" are exported by default. Either can be requested individually, or renamed. They are generated by Sub::Exporter, so consult its documentation for more information. Both can be generated with the option "method" which requests that a method other than "read_handle" is called with the created IO::Handle. read_file Your::Pkg->read_file($filename); If generated, the "read_file" export attempts to open the named file for reading, and then calls "read_handle" on the opened handle. Any arguments after $filename are passed along after to "read_handle". read_string Your::Pkg->read_string($string); If generated, the "read_string" creates an IO::String handle from the given string, and then calls "read_handle" on the opened handle. Any arguments after $string are passed along after to "read_handle". AUTHOR
Ricardo SIGNES <rjbs@cpan.org> COPYRIGHT AND LICENSE
This software is copyright (c) 2008 by Ricardo SIGNES. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.16.3 2013-06-18 Mixin::Linewise::Readers(3)
All times are GMT -4. The time now is 11:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy