Chun Tat David Chu
2008-Apr-17 18:01 UTC
[Fedora-directory-users] Question on hierarchy tree deletion
Hi group, I''ve a question about deleting the hierarchy tree using the Fedora DS provided command line utilities (e.g. ldapdelete, ldapsearch, ldapmodify and etc). Originally, I''m using the "ldapdelete" command from the openldapclient package with the "-r" flag to do recursive delete on the hierarchy tree, but I want to know if there''s anyway I can achieve the same effect by using command line utilities from the Fedora DS package. My original thought is to use ldapsearch, set it to return only the "dn" attribute and sorted by "createtimestamp" attribute. Then use the returned result and run the ldapdelete command. Assuming a child entry must have a later "createtimestamp" then parent entry. However, the result returned back from ldapsearch is in ascending order of the "createtimestamp" attribute. Is there a way to tell the ldapsearch command to sort returned result in descending order? or Is there a more efficient way to delete a hierarchy tree through command line? Thanks! David
Chun Tat David Chu
2008-Apr-17 18:32 UTC
Re: [Fedora-directory-users] Question on hierarchy tree deletion
Hi group, I figured out how to sort in descending order using ldapsearch. By default, it will always sort in ascending order. If I need to sort in descending then I need to add a "-" prefix before my attribute name. (e.g. -S -createtimestamp). In addition, I can only get the descending search work only if I specify the sorting to be done by the server by passing the "-x" flag. I still have the question about what is the best way to delete a hierarchy tree using command line utility provided by Fedora-DS package. My current plan is to do a ldapsearch with subtree scope and sort the createtimestamp attribute in descending order. Then take the output and run it with ldapdelete. Thanks! David On Thu, Apr 17, 2008 at 2:01 PM, Chun Tat David Chu < beyonddc.storage@gmail.com> wrote:> Hi group, > > I''ve a question about deleting the hierarchy tree using the Fedora DS > provided command line utilities (e.g. ldapdelete, ldapsearch, ldapmodify and > etc). > > Originally, I''m using the "ldapdelete" command from the openldapclient > package with the "-r" flag to do recursive delete on the hierarchy tree, but > I want to know if there''s anyway I can achieve the same effect by using > command line utilities from the Fedora DS package. > > My original thought is to use ldapsearch, set it to return only the "dn" > attribute and sorted by "createtimestamp" attribute. Then use the returned > result and run the ldapdelete command. Assuming a child entry must have a > later "createtimestamp" then parent entry. However, the result returned > back from ldapsearch is in ascending order of the "createtimestamp" > attribute. > > Is there a way to tell the ldapsearch command to sort returned result in > descending order? or > Is there a more efficient way to delete a hierarchy tree through command > line? > > Thanks! > > David >
J. Hartman
2008-Apr-18 10:41 UTC
Re: [Fedora-directory-users] Question on hierarchy tree deletion
Hi, I''ve done subtree deletion sometimes by sorting based on DN length. Delete longest DNs first and it''s certain that they are the leafs. The whole thing can be done in a one-liner. -Joona On Thu, Apr 17, 2008 at 9:32 PM, Chun Tat David Chu < beyonddc.storage@gmail.com> wrote:> Hi group, > > I figured out how to sort in descending order using ldapsearch. > > By default, it will always sort in ascending order. If I need to sort in > descending then I need to add a "-" prefix before my attribute name. (e.g. > -S -createtimestamp). > > In addition, I can only get the descending search work only if I specify > the sorting to be done by the server by passing the "-x" flag. > > I still have the question about what is the best way to delete a hierarchy > tree using command line utility provided by Fedora-DS package. > > My current plan is to do a ldapsearch with subtree scope and sort the > createtimestamp attribute in descending order. Then take the output and run > it with ldapdelete. > > Thanks! > > David > > > On Thu, Apr 17, 2008 at 2:01 PM, Chun Tat David Chu < > beyonddc.storage@gmail.com> wrote: > > > Hi group, > > > > I''ve a question about deleting the hierarchy tree using the Fedora DS > > provided command line utilities (e.g. ldapdelete, ldapsearch, ldapmodify and > > etc). > > > > Originally, I''m using the "ldapdelete" command from the openldapclient > > package with the "-r" flag to do recursive delete on the hierarchy tree, but > > I want to know if there''s anyway I can achieve the same effect by using > > command line utilities from the Fedora DS package. > > > > My original thought is to use ldapsearch, set it to return only the "dn" > > attribute and sorted by "createtimestamp" attribute. Then use the returned > > result and run the ldapdelete command. Assuming a child entry must have a > > later "createtimestamp" then parent entry. However, the result returned > > back from ldapsearch is in ascending order of the "createtimestamp" > > attribute. > > > > Is there a way to tell the ldapsearch command to sort returned result in > > descending order? or > > Is there a more efficient way to delete a hierarchy tree through command > > line? > > > > Thanks! > > > > David > > > > > -- > Fedora-directory-users mailing list > Fedora-directory-users@redhat.com > https://www.redhat.com/mailman/listinfo/fedora-directory-users > >
Michael Ströder
2008-Apr-18 10:52 UTC
Re: [Fedora-directory-users] Question on hierarchy tree deletion
HI! In web2ldap I''ve implemented in Python the recursive tree deletion also based on various operational attributes like hasSubordinates, numSubordinates etc. It also catches the exception ldap.NOT_ALLOWED_ON_NONLEAF and starts a new search then. Also exceptions ldap.SIZELIMIT_EXCEEDED and ldap.ADMINLIMIT_EXCEEDED are gracefully handled for large result sets hitting a server-side limit. I''m not sure whether it''s really "optimal" but I think I''ve managed to lower the number of search requests needed without having to rely on any sorting. Ciao, Michael. Chun Tat David Chu wrote:> Hi group, > > I''ve a question about deleting the hierarchy tree using the Fedora DS > provided command line utilities (e.g. ldapdelete, ldapsearch, ldapmodify > and etc). > > Originally, I''m using the "ldapdelete" command from the openldapclient > package with the "-r" flag to do recursive delete on the hierarchy tree, > but I want to know if there''s anyway I can achieve the same effect by > using command line utilities from the Fedora DS package. > > My original thought is to use ldapsearch, set it to return only the "dn" > attribute and sorted by "createtimestamp" attribute. Then use the > returned result and run the ldapdelete command. Assuming a child entry > must have a later "createtimestamp" then parent entry. However, the > result returned back from ldapsearch is in ascending order of the > "createtimestamp" attribute. > > Is there a way to tell the ldapsearch command to sort returned result in > descending order? or > Is there a more efficient way to delete a hierarchy tree through command > line? > > Thanks! > > David > > > ------------------------------------------------------------------------ > > -- > Fedora-directory-users mailing list > Fedora-directory-users@redhat.com > https://www.redhat.com/mailman/listinfo/fedora-directory-users-- Michael Ströder Klauprechtstr. 11 Dipl.-Inform. D-76137 Karlsruhe, Germany Tel.: +49 721 8304316 Mobil: +49 170 2391920 E-Mail: michael@stroeder.com http://www.stroeder.com
Chun Tat David Chu
2008-Apr-18 14:26 UTC
Re: [Fedora-directory-users] Question on hierarchy tree deletion
Joona, Do you mind to show me how to sort by DN length? and execute the ldapdelete? I looked at it a bit but I couldn''t figure out. Thanks! David On Fri, Apr 18, 2008 at 6:41 AM, J. Hartman <joona.hartman@gmail.com> wrote:> Hi, > > I''ve done subtree deletion sometimes by sorting based on DN length. Delete > longest DNs first and it''s certain that they are the leafs. The whole thing > can be done in a one-liner. > > -Joona > > On Thu, Apr 17, 2008 at 9:32 PM, Chun Tat David Chu < > beyonddc.storage@gmail.com> wrote: > > > Hi group, > > > > I figured out how to sort in descending order using ldapsearch. > > > > By default, it will always sort in ascending order. If I need to sort > > in descending then I need to add a "-" prefix before my attribute name. > > (e.g. -S -createtimestamp). > > > > In addition, I can only get the descending search work only if I specify > > the sorting to be done by the server by passing the "-x" flag. > > > > I still have the question about what is the best way to delete a > > hierarchy tree using command line utility provided by Fedora-DS package. > > > > My current plan is to do a ldapsearch with subtree scope and sort the > > createtimestamp attribute in descending order. Then take the output and run > > it with ldapdelete. > > > > Thanks! > > > > David > > > > > > On Thu, Apr 17, 2008 at 2:01 PM, Chun Tat David Chu < > > beyonddc.storage@gmail.com> wrote: > > > > > Hi group, > > > > > > I''ve a question about deleting the hierarchy tree using the Fedora DS > > > provided command line utilities (e.g. ldapdelete, ldapsearch, ldapmodify and > > > etc). > > > > > > Originally, I''m using the "ldapdelete" command from the openldapclient > > > package with the "-r" flag to do recursive delete on the hierarchy tree, but > > > I want to know if there''s anyway I can achieve the same effect by using > > > command line utilities from the Fedora DS package. > > > > > > My original thought is to use ldapsearch, set it to return only the > > > "dn" attribute and sorted by "createtimestamp" attribute. Then use the > > > returned result and run the ldapdelete command. Assuming a child entry must > > > have a later "createtimestamp" then parent entry. However, the result > > > returned back from ldapsearch is in ascending order of the "createtimestamp" > > > attribute. > > > > > > Is there a way to tell the ldapsearch command to sort returned result > > > in descending order? or > > > Is there a more efficient way to delete a hierarchy tree through > > > command line? > > > > > > Thanks! > > > > > > David > > > > > > > > > -- > > Fedora-directory-users mailing list > > Fedora-directory-users@redhat.com > > https://www.redhat.com/mailman/listinfo/fedora-directory-users > > > > > > -- > Fedora-directory-users mailing list > Fedora-directory-users@redhat.com > https://www.redhat.com/mailman/listinfo/fedora-directory-users > >
J. Hartman
2008-Apr-21 14:04 UTC
Re: [Fedora-directory-users] Question on hierarchy tree deletion
I can''t remember how exactly I did it, but I recall I used awk and sort
in
between to count the line length (awk) and do numeric sort on the resulting
line.
Something like this:
$ ldapsearch -b BASEDN "objectclass=*" | awk ''/dn:/
{l=length($0);
sub(/dn:/,""); print l $0}'' | sort -n | cut ... | ldapdelete
...
Gets a bit nasty but something like that should work.
Hope that helps!
On Fri, Apr 18, 2008 at 5:26 PM, Chun Tat David Chu <
beyonddc.storage@gmail.com> wrote:
> Joona,
>
> Do you mind to show me how to sort by DN length? and execute the
> ldapdelete?
> I looked at it a bit but I couldn''t figure out.
>
> Thanks!
>
> David
>
>
> On Fri, Apr 18, 2008 at 6:41 AM, J. Hartman <joona.hartman@gmail.com>
> wrote:
>
> > Hi,
> >
> > I''ve done subtree deletion sometimes by sorting based on DN
length.
> > Delete longest DNs first and it''s certain that they are the
leafs. The whole
> > thing can be done in a one-liner.
> >
> > -Joona
> >
> > On Thu, Apr 17, 2008 at 9:32 PM, Chun Tat David Chu <
> > beyonddc.storage@gmail.com> wrote:
> >
> > > Hi group,
> > >
> > > I figured out how to sort in descending order using ldapsearch.
> > >
> > > By default, it will always sort in ascending order. If I need to
sort
> > > in descending then I need to add a "-" prefix before my
attribute name.
> > > (e.g. -S -createtimestamp).
> > >
> > > In addition, I can only get the descending search work only if I
> > > specify the sorting to be done by the server by passing the
"-x" flag.
> > >
> > > I still have the question about what is the best way to delete a
> > > hierarchy tree using command line utility provided by Fedora-DS
package.
> > >
> > > My current plan is to do a ldapsearch with subtree scope and sort
the
> > > createtimestamp attribute in descending order. Then take the
output and run
> > > it with ldapdelete.
> > >
> > > Thanks!
> > >
> > > David
> > >
> > >
> > > On Thu, Apr 17, 2008 at 2:01 PM, Chun Tat David Chu <
> > > beyonddc.storage@gmail.com> wrote:
> > >
> > > > Hi group,
> > > >
> > > > I''ve a question about deleting the hierarchy tree
using the Fedora
> > > > DS provided command line utilities (e.g. ldapdelete,
ldapsearch, ldapmodify
> > > > and etc).
> > > >
> > > > Originally, I''m using the "ldapdelete"
command from the
> > > > openldapclient package with the "-r" flag to do
recursive delete on the
> > > > hierarchy tree, but I want to know if there''s
anyway I can achieve the same
> > > > effect by using command line utilities from the Fedora DS
package.
> > > >
> > > > My original thought is to use ldapsearch, set it to return
only the
> > > > "dn" attribute and sorted by
"createtimestamp" attribute. Then use the
> > > > returned result and run the ldapdelete command. Assuming a
child entry must
> > > > have a later "createtimestamp" then parent entry.
However, the result
> > > > returned back from ldapsearch is in ascending order of the
"createtimestamp"
> > > > attribute.
> > > >
> > > > Is there a way to tell the ldapsearch command to sort
returned
> > > > result in descending order? or
> > > > Is there a more efficient way to delete a hierarchy tree
through
> > > > command line?
> > > >
> > > > Thanks!
> > > >
> > > > David
> > > >
> > >
> > >
> > > --
> > > Fedora-directory-users mailing list
> > > Fedora-directory-users@redhat.com
> > > https://www.redhat.com/mailman/listinfo/fedora-directory-users
> > >
> > >
> >
> > --
> > Fedora-directory-users mailing list
> > Fedora-directory-users@redhat.com
> > https://www.redhat.com/mailman/listinfo/fedora-directory-users
> >
> >
>
> --
> Fedora-directory-users mailing list
> Fedora-directory-users@redhat.com
> https://www.redhat.com/mailman/listinfo/fedora-directory-users
>
>
Chun Tat David Chu
2008-Apr-21 14:30 UTC
Re: [Fedora-directory-users] Question on hierarchy tree deletion
Great! I''ll try that out. Thanks, David On Mon, Apr 21, 2008 at 10:04 AM, J. Hartman <joona.hartman@gmail.com> wrote:> I can''t remember how exactly I did it, but I recall I used awk and sort in > between to count the line length (awk) and do numeric sort on the resulting > line. > > Something like this: > > $ ldapsearch -b BASEDN "objectclass=*" | awk ''/dn:/ {l=length($0); > sub(/dn:/,""); print l $0}'' | sort -n | cut ... | ldapdelete ... > > Gets a bit nasty but something like that should work. > > Hope that helps! > > > On Fri, Apr 18, 2008 at 5:26 PM, Chun Tat David Chu < > beyonddc.storage@gmail.com> wrote: > > > Joona, > > > > Do you mind to show me how to sort by DN length? and execute the > > ldapdelete? > > I looked at it a bit but I couldn''t figure out. > > > > Thanks! > > > > David > > > > > > On Fri, Apr 18, 2008 at 6:41 AM, J. Hartman <joona.hartman@gmail.com> > > wrote: > > > > > Hi, > > > > > > I''ve done subtree deletion sometimes by sorting based on DN length. > > > Delete longest DNs first and it''s certain that they are the leafs. The whole > > > thing can be done in a one-liner. > > > > > > -Joona > > > > > > On Thu, Apr 17, 2008 at 9:32 PM, Chun Tat David Chu < > > > beyonddc.storage@gmail.com> wrote: > > > > > > > Hi group, > > > > > > > > I figured out how to sort in descending order using ldapsearch. > > > > > > > > By default, it will always sort in ascending order. If I need to > > > > sort in descending then I need to add a "-" prefix before my attribute > > > > name. (e.g. -S -createtimestamp). > > > > > > > > In addition, I can only get the descending search work only if I > > > > specify the sorting to be done by the server by passing the "-x" flag. > > > > > > > > I still have the question about what is the best way to delete a > > > > hierarchy tree using command line utility provided by Fedora-DS package. > > > > > > > > My current plan is to do a ldapsearch with subtree scope and sort > > > > the createtimestamp attribute in descending order. Then take the output and > > > > run it with ldapdelete. > > > > > > > > Thanks! > > > > > > > > David > > > > > > > > > > > > On Thu, Apr 17, 2008 at 2:01 PM, Chun Tat David Chu < > > > > beyonddc.storage@gmail.com> wrote: > > > > > > > > > Hi group, > > > > > > > > > > I''ve a question about deleting the hierarchy tree using the Fedora > > > > > DS provided command line utilities (e.g. ldapdelete, ldapsearch, ldapmodify > > > > > and etc). > > > > > > > > > > Originally, I''m using the "ldapdelete" command from the > > > > > openldapclient package with the "-r" flag to do recursive delete on the > > > > > hierarchy tree, but I want to know if there''s anyway I can achieve the same > > > > > effect by using command line utilities from the Fedora DS package. > > > > > > > > > > My original thought is to use ldapsearch, set it to return only > > > > > the "dn" attribute and sorted by "createtimestamp" attribute. Then use the > > > > > returned result and run the ldapdelete command. Assuming a child entry must > > > > > have a later "createtimestamp" then parent entry. However, the result > > > > > returned back from ldapsearch is in ascending order of the "createtimestamp" > > > > > attribute. > > > > > > > > > > Is there a way to tell the ldapsearch command to sort returned > > > > > result in descending order? or > > > > > Is there a more efficient way to delete a hierarchy tree through > > > > > command line? > > > > > > > > > > Thanks! > > > > > > > > > > David > > > > > > > > > > > > > > > > > -- > > > > Fedora-directory-users mailing list > > > > Fedora-directory-users@redhat.com > > > > https://www.redhat.com/mailman/listinfo/fedora-directory-users > > > > > > > > > > > > > > -- > > > Fedora-directory-users mailing list > > > Fedora-directory-users@redhat.com > > > https://www.redhat.com/mailman/listinfo/fedora-directory-users > > > > > > > > > > -- > > Fedora-directory-users mailing list > > Fedora-directory-users@redhat.com > > https://www.redhat.com/mailman/listinfo/fedora-directory-users > > > > > > -- > Fedora-directory-users mailing list > Fedora-directory-users@redhat.com > https://www.redhat.com/mailman/listinfo/fedora-directory-users > >