Please help

Discussion in 'Ruby' started by Lokesh Agrawal, Mar 11, 2008.

  1. Hi All,

    I have written a scipt.


    require 'rubygems'
    require 'net/ldap'
    require "env_variable.rb"


    ldap = Net::LDAP.new :host => '10.44.169.24',
    :port => 389,
    :auth => {
    :method => :simple,
    :username => "cn=Manager,dc=ibm,dc=com",
    :password => "secret"
    }


    filter = Net::LDAP::Filter.eq( "mail", $email )
    treebase = "dc=ibm,dc=com"
    attrs = ["status"]
    ldap.search( :base => treebase, :filter => filter, :attributes =>
    attrs ) do |entry|
    entry.each do |attribute, values|
    $i = 1
    values.each do |$status|
    end
    puts $status
    end
    end


    and I am getting output
    Inactive
    mail=$email,ou=people,o=external,dc=ibm,dc=com


    means $status variable is holding text Inactive first time and second
    time its value is
    mail=$email,ou=people,o=external,dc=ibm,dc=com (first value get
    replaced by new value)


    I want to take both the values in variable or in array.


    Can anyone help me please.


    Thanks and Regards
    Lokesh Agrawal
    --
    Posted via http://www.ruby-forum.com/.
    Lokesh Agrawal, Mar 11, 2008
    #1
    1. Advertising

  2. Lokesh Agrawal

    Todd Benson Guest

    On Tue, Mar 11, 2008 at 5:35 AM, Lokesh Agrawal
    <> wrote:
    > Hi All,
    >
    > I have written a scipt.
    >
    >
    > require 'rubygems'
    > require 'net/ldap'
    > require "env_variable.rb"
    >
    >
    > ldap = Net::LDAP.new :host => '10.44.169.24',
    > :port => 389,
    > :auth => {
    > :method => :simple,
    > :username => "cn=Manager,dc=ibm,dc=com",
    > :password => "secret"
    > }
    >
    >
    > filter = Net::LDAP::Filter.eq( "mail", $email )
    > treebase = "dc=ibm,dc=com"
    > attrs = ["status"]
    > ldap.search( :base => treebase, :filter => filter, :attributes =>
    > attrs ) do |entry|
    > entry.each do |attribute, values|
    > $i = 1


    It is not clear what the purpose of $i is here.

    > values.each do |$status|
    > end


    I'm assuming that end was unintended/misplaced.

    > puts $status
    > end
    > end
    >
    >
    > and I am getting output
    > Inactive
    > mail=$email,ou=people,o=external,dc=ibm,dc=com
    >
    >
    > means $status variable is holding text Inactive first time and second
    > time its value is
    > mail=$email,ou=people,o=external,dc=ibm,dc=com (first value get
    > replaced by new value)
    >
    >
    > I want to take both the values in variable or in array.


    I haven't used ldap, but maybe something similar to this might work...

    a = [1,2,3]
    b = [] #initialize before block
    a.each {|i| b << a} #append
    p b

    Todd
    Todd Benson, Mar 11, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JC
    Replies:
    4
    Views:
    7,968
    Jeff C
    Jul 8, 2004
  2. Replies:
    4
    Views:
    508
    Chris Uppal
    May 5, 2005
  3. KK
    Replies:
    2
    Views:
    552
    Big Brian
    Oct 14, 2003
  4. MuZZy
    Replies:
    7
    Views:
    1,749
    Mike Hewson
    Jan 7, 2005
  5. mera
    Replies:
    7
    Views:
    1,103
Loading...

Share This Page