LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 04-04-2009, 08:50 PM   #1
llattan
LQ Newbie
 
Registered: Apr 2009
Location: Rosario
Distribution: Redhat Enterprise
Posts: 12

Rep: Reputation: 0
Sort attributes by name for each entry in ldapsearch output (ldap database export)


I need to sort attributes by name for each entry in ldapsearch output
(-S "" sort entries by name, but not their attributes)

I need this to compare consistency of 2 ldap databases after the wan connection link up (in multimaster configuration). Because the time of writing for each attribute could differ, the order could not be the same.


My "export" script

HOSTNAME=localhost
BINDDN="cn=manager,dc=example,dc=com"
BASE="dc=example,dc=com"
PASSWORD=`cat /etc/ldap.secret`

/usr/bin/ldapsearch -LLL -x -h $HOSTNAME -D "$BINDDN" -w "$PASSWORD" -b "$BASE" -S ""


Thanks in advance.
Leandro.
 
Old 08-03-2023, 08:28 AM   #2
remigiusz
LQ Newbie
 
Registered: Aug 2023
Posts: 1

Rep: Reputation: 0
Could not find it either. Ended up with brute force solution with sorting within sections of ldapsearch output like:

/usr/bin/ldapsearch -LLL (...) | sort_within_sections.sh

where sort_within_sections.sh looks like:
Quote:
$ cat sort_within_sections.sh
#!/bin/bash

# Author: Remigiusz Boguszewicz
# Purpose: Sort with sections, seemed like a job for oneliner, but I could not
# find an elegant solution, so this script had to be born
# Input: standard input or file provided as parameter
# Output: standard output

V_TMP_FILE="/tmp/sort_within_sections.tmp"
rm -f $V_TMP_FILE

while read line
do
if [ -z "$line" ]; then
#echo "[debug] we have separator, which is empty line"
#echo "[debug] print everything from section now, then print separator"
if [ -f $V_TMP_FILE ]; then
#echo "[debug] File $V_TMP_FILE exists. Printing its contents sorted."
cat $V_TMP_FILE | sort
rm -f $V_TMP_FILE
fi
echo "$line"
else
#echo "[debug] append line to temp file"
echo "$line" >> $V_TMP_FILE
fi
done < "${1:-/dev/stdin}"
---
Regards
Remigiusz Boguszewicz

Last edited by remigiusz; 08-03-2023 at 08:30 AM.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to get ldap to bind to Active Directory server, but am able to ldapsearch kcorupe Linux - Server 2 08-03-2012 02:57 AM
LDAP > ldapsearch doesn't print the entries when bound as normal user cbonar Linux - Server 2 09-22-2007 01:19 PM
ldap with limited attributes nemo3383 Linux - Networking 0 06-03-2005 12:52 PM
OpenLDAP, ldapsearch: how to list all attributes Hko Linux - Networking 0 08-15-2004 10:43 AM
ldap-abook unable to get street name in ldap-entry Jingle Linux - Software 1 06-06-2004 07:13 PM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 11:23 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