Forum Discussion
convert ldapsearch result into external datagroup format
I come cross a
requirement to convert a txt file into external datagroup format in background.
The source file is
the result from ldapsearch, something like this:
dn:
r1+sn=test,ou=people,dc=my-domain,dc=com
cn: client1
mailHost: mailserver1
dn:
r2+sn=test,ou=people,dc=my-domain,dc=com
cn: client2
mailHost: mailserver2
I need a scripts
to convert it into external datagroup format like this:
"client1" := "mailserver1",
“client2" := "mailserver2",
Then use datagroup
as a reference to distribution traffic to mailservers.
If anyone has
similar scripts on hand, please share me.
Thanks a lot!!
- HamishCirrocumulusGive me a couple of hours. I have some perl scripts that do stuff like this. I will dig them out.
- hooleylistCirrostratus
!/usr/bin/perl if($ARGV < 1) { print $ARGV."\n"; print "$0 [ldifffile] [datagroupfile]\n"; exit(0); } open(LDIFFFILE, "<".$ARGV[0]) or die "Can't open ".$ARGV[0]."\n"; open(DATAGROUP, ">".$ARGV[1]) or die "Can't open ".$ARGV[1]."\n"; while() { my($line) = $_; chomp($line); if ($line =~ /^cn:/) { print DATAGROUP "\"".substr($line,index($line,': ')+2)."\" := \""; } if ($line =~ /^mailHost:/) { print DATAGROUP substr($line, index($line,':')+2)."\"\n"; } } close(LDIFFFILE); close(DATAGROUP);
- hooleylistCirrostratusAnd an even simpler awk example from James Quinby:
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com