From: Eugene Prokopiev <john@rmts.donpac.ru>
To: community@altlinux.ru
Subject: Re: [Comm] Ldap scripting: bash vs perl
Date: Wed, 26 May 2004 10:06:26 +0400
Message-ID: <40B433E2.5050303@rmts.donpac.ru> (raw)
In-Reply-To: <40B1C951.3030204@rmts.donpac.ru>
Не смог удержаться и проделал то же самое на php и ruby. Вот что
получилось (приведены все варианты):
# time ./make_ldap_filter.sh > /dev/null
0.05user 0.03system 0:00.08elapsed 89%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (825major+194minor)pagefaults 0swaps
# time ./make_ldap_filter.php > /dev/null
0.63user 0.51system 0:04.46elapsed 25%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (8903major+196minor)pagefaults 0swaps
# time ./make_ldap_filter.rb > /dev/null
bind: Success
0.37user 0.04system 0:02.21elapsed 18%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (488major+211minor)pagefaults 0swaps
# time ./make_ldap_filter.py > /dev/null
0.40user 0.10system 0:01.70elapsed 29%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (720major+349minor)pagefaults 0swaps
# time ./make_ldap_filter.pl allowNat > /dev/null
2.43user 0.13system 0:02.57elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (437major+833minor)pagefaults 0swaps
Ну а вот код:
# cat ./make_ldap_filter.sh
#!/bin/bash
ldapsearch -LLL "(&(objectClass=internetAccess) ("$1"=TRUE))" | grep
fixed-address | awk '{print $3}'
# cat ./make_ldap_filter.php
#!/usr/bin/php
<?php
$ds=ldap_connect("localhost");
if ($ds) {
$r=ldap_bind($ds);
$sr=ldap_search($ds,"dc=myserver, dc=myprovider, dc=ru",
"allowNat=TRUE");
$info = ldap_get_entries($ds, $sr);
for ($i=0; $i<$info["count"]; $i++) {
echo "Host is: ". $info[$i]["cn"][0] ."\n";
}
ldap_close($ds);
}
?>
# cat ./make_ldap_filter.rb
#!/usr/bin/ruby
require "ldap"
LDAP::Conn.new("localhost").bind{|conn|
conn.perror("bind")
begin
conn.search("dc=myserver, dc=myprovider, dc=ru",
LDAP::LDAP_SCOPE_SUBTREE,
"(objectclass=*)"){|e|
p e.vals("cn")
p e.to_hash()
}
rescue LDAP::ResultError => msg
$stderr.print(msg)
end
}
# cat ./make_ldap_filter.py
#!/usr/bin/env python
import ldap, re
try:
ldapConnection = ldap.open('myserver.myprovider.ru')
ldapConnection.simple_bind_s('', '')
except ldap.LDAPError, e:
print e
out = []
baseDN = 'cn=Network,dc=myserver,dc=myprovider,dc=ru'
searchScope = ldap.SCOPE_SUBTREE
_result = ldapConnection.search_s(baseDN, searchScope,
'(&(objectclass=internetAccess)(allowNat=TRUE))', ['dhcpStatements'])
if _result:
out = filter(lambda x: re.search('fixed-address.*', x), map(lambda x:
x[1]['dhcpStatements'][0], _result))
print out
ldapConnection.unbind_s()
# cat ./make_ldap_filter.pl
#!/usr/bin/perl
use Net::LDAP;
$ldap = Net::LDAP->new('localhost') or die "$@";
$ldap->bind;
$mesg = $ldap->search(
base => "dc=myserver, dc=myprovider, dc=ru",
filter => sprintf("(&(objectClass=internetAccess) (%s=TRUE))", @ARGV)
);
$mesg->code && die $mesg->error;
foreach $entry ($mesg->all_entries) {
foreach my $value ($entry->get_value('dhcpStatements')) {
if ($value =~ /fixed-address /) {
print "$'\n";
}
}
}
$ldap->unbind;
Еще одним тормозом оказался php ;)
Но тут уже дело в том, что завершение работы скрипта и возврат к #
происходит слишком медленно, сам поиск (на глаз) вроде не медленнее прочих.
--
С уважением, Прокопьев Евгений
next prev parent reply other threads:[~2004-05-26 6:06 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-24 10:07 Eugene Prokopiev
2004-05-24 10:10 ` Alexey Morsov
2004-05-24 10:36 ` Eugene Prokopiev
2004-05-24 11:06 ` Mike Lykov
2004-05-24 11:10 ` Eugene Prokopiev
2004-05-24 10:22 ` Klimchev Konstantin
2004-05-24 10:29 ` Eugene Prokopiev
2004-05-24 10:45 ` Alexey Morsov
2004-05-24 10:59 ` Eugene Prokopiev
2004-05-24 11:22 ` Klimchev Konstantin
2004-05-24 11:32 ` Eugene Prokopiev
2004-05-25 7:43 ` Klimchev Konstantin
2004-05-25 8:21 ` Mike Lykov
2004-05-25 8:31 ` Klimchev Konstantin
2004-05-25 8:51 ` Mike Lykov
2004-05-25 8:58 ` Klimchev Konstantin
2004-05-25 10:43 ` [Comm] " Alexey Tourbin
2004-05-26 6:06 ` Eugene Prokopiev [this message]
2004-05-26 6:14 ` [Comm] " Klimchev Konstantin
2004-05-26 8:04 ` Eugene Prokopiev
2004-05-26 8:20 ` Klimchev Konstantin
2004-05-26 9:08 ` Eugene Prokopiev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=40B433E2.5050303@rmts.donpac.ru \
--to=john@rmts.donpac.ru \
--cc=community@altlinux.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
ALT Linux Community general discussions
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
public-inbox-index community
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.community
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git