ldapsearch Zeilenumbruch

Alle weiteren Dienste, die nicht in die drei oberen Foren gehören.
Antworten
Benutzeravatar
HelsAett
Beiträge: 749
Registriert: 18.03.2003 18:25:00

ldapsearch Zeilenumbruch

Beitrag von HelsAett » 14.11.2012 11:14:23

Hallo @ll

bei der Abfrage an den LDAP

Code: Alles auswählen

ldapsearch -h 192.168.0.1 -p 389 -x -D cn=BLABLA,ou=BLA,o=BLA -w GEHEIM cn=USER
liefert mir die Konsole, die Werte mit Umbrüchen und Eingerückten Werten zurück:

Code: Alles auswählen

groupMembership: cn=USER,ou=BLA,ou=BLA (PW),ou=HOME,o=MEIN-
 DIR
wie kann ich die Ausgabe in einer Zeile zurück bekommen, hat da jemand eine Idee?

Code: Alles auswählen

groupMembership: cn=USER,ou=BLA,ou=BLA (PW),ou=HOME,o=MEIN-DIR
Danke und Gruß

Cae
Beiträge: 6349
Registriert: 17.07.2011 23:36:39
Wohnort: 2130706433

Re: ldapsearch Zeilenumbruch

Beitrag von Cae » 16.11.2012 01:58:22

Falls $COLS ausgewertet wird, kannst du es temporaer auf einen irre hohen Wert hochschrauben. Sonst kannst du mal gucken, ob das Verhalten in einer Pipe

Code: Alles auswählen

$ ldapsearch blah blubb | cat
dasselbe ist (das waere unschoen).

Im Notfall kann man etwas awk dahinter klemmen:

Code: Alles auswählen

$ mawk '{ if (/^[ ]+/) { sub(/^[ ]+/, ""); buf = buf $0 } else { buf = buf ((i++) ? "\n" : "") $0 }} END { print buf }'
foo bar baz>
 <fnord>
 <foo   > 
line 2>
 <foo>
  <doublespace>
foo bar baz><fnord><foo   > 
line 2><foo><doublespace>
$ 
Die ersten sechs Zeilen sind die Eingabe (mit EOF, also ^D abgeschlossen), danach folgt die Ausgabe. Sofern vorne ein oder mehrere Spaces stehen, werden sie abgeschnippelt und die Zeile an einen Puffer angehaengt, welcher ab der zweiten nicht-Whitespace-Zeile um eine Newline und die aktuelle Zeile ergaenzt wird.

Gruss Cae
If universal surveillance were the answer, lots of us would have moved to the former East Germany. If surveillance cameras were the answer, camera-happy London, with something like 500,000 of them at a cost of $700 million, would be the safest city on the planet.

—Bruce Schneier

Benutzeravatar
habakug
Moderator
Beiträge: 4314
Registriert: 23.10.2004 13:08:41
Lizenz eigener Beiträge: MIT Lizenz

Re: ldapsearch Zeilenumbruch

Beitrag von habakug » 16.11.2012 09:07:12

Hallo!

Das ist in der RFC2849 [1] für das LDIF-Format geregelt:
2) Any non-empty line, including comment lines, in an LDIF file
MAY be folded by inserting a line separator (SEP) and a SPACE.
Folding MUST NOT occur before the first character of the line.
In other words, folding a line into two lines, the first of
which is empty, is not permitted. Any line that begins with a
single space MUST be treated as a continuation of the previous
(non-empty) line. When joining folded lines, exactly one space
character at the beginning of each continued line must be
discarded. Implementations SHOULD NOT fold lines in the middle
of a multi-byte UTF-8 character.
Es sollte mit diesem Wissen recht einfach sein, die Zeile, die mit einen Leerzeichen beginnt, an die vorhergehende anzuhängen.

Gruß, habakug

[1] http://www.ietf.org/rfc/rfc2849.txt
( # = root | $ = user | !! = mod ) (Vor der PN) (Debianforum-Wiki) (NoPaste)

Cae
Beiträge: 6349
Registriert: 17.07.2011 23:36:39
Wohnort: 2130706433

Re: ldapsearch Zeilenumbruch

Beitrag von Cae » 16.11.2012 13:33:19

Mit dieser Ergaenzung muessen bei meiner awk-Zeile oben beide Regex' veraendert werden, damit sie RFC-konform ist: /^[ ]+/ wird jeweils zu /^ /. Die eckigen Klammern [] in den Regex' waren zuvor schon ueberfluessig gewesen.
Der Output aendert sich:

Code: Alles auswählen

$ mawk '{ if (/^ /) { sub(/^ /, ""); buf = buf $0 } else { buf = buf ((i++) ? "\n" : "") $0 }} END { print buf }'  
foo bar baz>
 <fnord>
 <foo   >
line 2>
 <foo>
  <doublespace>
foo bar baz><fnord><foo   >
line 2><foo> <doublespace>
Man beachte das hinzu gekommene Space bei foo> <doublespace.

Gruss Cae
If universal surveillance were the answer, lots of us would have moved to the former East Germany. If surveillance cameras were the answer, camera-happy London, with something like 500,000 of them at a cost of $700 million, would be the safest city on the planet.

—Bruce Schneier

Benutzeravatar
habakug
Moderator
Beiträge: 4314
Registriert: 23.10.2004 13:08:41
Lizenz eigener Beiträge: MIT Lizenz

Re: ldapsearch Zeilenumbruch

Beitrag von habakug » 16.11.2012 21:58:37

Hallo!

Oder so mit sed:

Code: Alles auswählen

# ldapsearch .... | sed -e ':a' -e '$!N;s/\r\?\n //;ta' -e 'P;D'
Gruß, habakug
( # = root | $ = user | !! = mod ) (Vor der PN) (Debianforum-Wiki) (NoPaste)

Antworten