Hi,

I did the same way you told me. Still not returning any output
irb
irb(main):001:0> logfile = '/home/suppalapati/java.txt'
=> "/home/suppalapati/java.txt"
irb(main):002:0> line_num=0
=> 0
irb(main):004:0> require 'facter/util/file_read'
=> true
irb(main):005:0> log = Facter::Util::FileRead.read(logfile)
=> "\n/usr/java/jdk1.7.0_25/jre/bin/java
-version\n/usr/java/jdk1.7.0_25/bin/java
-version\n/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.45.x86_64/jre/bin/java
-version\n/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin/java
-version\n\n"
irb(main):006:0> unless log.nil?
irb(main):007:1> log.each_line do |line|
irb(main):008:2* if line.include?('java')
irb(main):009:3> line_num += 1
irb(main):010:3> javaid, val = %x[#{log}]
irb(main):011:3>  Facter.add("java_#{javaid}") do
irb(main):012:4* puts val
irb(main):013:4> end
irb(main):014:3> puts val1
irb(main):015:3> end


Let me know where i am doing mistake

On Wed, Oct 8, 2014 at 8:18 PM, Andy Parker <[email protected]> wrote:

> On Wed, Oct 8, 2014 at 12:59 PM, Supriya Uppalapati <
> [email protected]> wrote:
>
>> Hi Andrey,
>>
>> When i tried your example, It is not returning any values
>>
>> require 'facter/util/file_read'
>> => true
>> irb(main):005:0> log =
>> Facter::Util::FileRead.read("/home/suppalapati/java.txt")
>> =>
>> "\n/usr/java/jdk1.7.0_25/jre/bin/java\n/usr/java/jdk1.7.0_25/bin/java\n/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.45.x86_64/jre/bin/java\n/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin/java\n\n"
>> irb(main):006:0> log.each_line do |line|
>> irb(main):007:1* javaid, val = %x{line}
>> irb(main):008:1> javaid, val = %x{java}
>> irb(main):009:1>  val = %x{java}
>> irb(main):010:1>  val = %x{line}
>> irb(main):011:1>  val = %x{log}
>> irb(main):012:1>  val = %x{i}
>> irb(main):013:1> value = %x['#{i} -version']
>> irb(main):014:1> val
>> irb(main):015:1>
>>
>>
> You won't get any output until you enter "end". IRB will only execute
> complete statements. Instead of simply assigning the output of the command
> to a variable in irb you'll be better off if you print it out as well.
>
> log.each_line do |line|
>   val = %{#{line}}
>   puts val
> end
>
>
>>
>> Let me know
>>
>> On Wed, Oct 8, 2014 at 3:45 PM, Andy Parker <[email protected]> wrote:
>>
>>> On Wed, Oct 8, 2014 at 12:32 PM, Supriya Uppalapati <
>>> [email protected]> wrote:
>>>
>>>> Hi,
>>>>
>>>> It isn't executing anything. it means it is not showing individual fact
>>>> for each java version. yes my facts(java_version_count ) is showing me how
>>>> many lines(means java) i have in java.txt. yes i placed in wright
>>>> location.I followed the  link which you provided me.
>>>>
>>>> I feel some thing is wrong here, i think
>>>>
>>>>
>>> A useful tool to understand and debug ruby code is irb. With irb you can
>>> try out your code interactively. To try out some of your code here you can
>>> do:
>>>
>>> > irb
>>> 1.9.1 :001 > require 'facter'
>>>  => true
>>> 1.9.1 :004 > require 'facter/util/file_read'
>>>  => true
>>> 1.9.1 :005 > hosts = Facter::Util::FileRead.read("/etc/hosts")
>>>  => ....
>>> 1.9.1 :007 > hosts.each_line do |line|
>>> 1.9.1 :008 >     puts line
>>> 1.9.1 :009?>   end
>>>   ....
>>>
>>> *logfile = '/home/suppalapati/java.txt'*
>>>>
>>>> *line_num=0*
>>>>
>>>> *log = Facter::Util::FileRead.read(logfile)*
>>>> *unless log.nil?*
>>>> *  log.each_line do |line|*
>>>> *    if line.include?('java')*
>>>> *       line_num += 1*
>>>> *       javaid, val =  %x[ #{log} ]*
>>>>
>>>
>>> If you try running one of these lines you'll see what is happening:
>>>
>>> 1.9.1 :012 >   javaid, val = %x{java}
>>>   ...lots of output...
>>> 1.9.1 :013 > javaid
>>>   ...same output as above...
>>> 1.9.1 :014 > val
>>>   => nil
>>>
>>> So you are ending up with nil as the value of your fact and the name of
>>> the fact is the output of your command. You can't assign the output of a
>>> process execution to a list of variables, only the first variable will
>>> receive a value. You'll need to parse the output of that command to get
>>> whatever value it is that you are looking for.
>>>
>>>
>>>> *    Facter.add("java_#{javaid}") do*
>>>> *      setcode do*
>>>> *         val*
>>>>
>>>>
>>>> Can you correct me?
>>>>
>>>>
>>>> Thank You
>>>>
>>>> On Wed, Oct 8, 2014 at 3:26 PM, Andy Parker <[email protected]>
>>>> wrote:
>>>>
>>>>> On Wed, Oct 8, 2014 at 11:26 AM, Supriya Uppalapati <
>>>>> [email protected]> wrote:
>>>>>
>>>>>> Hi All,
>>>>>>
>>>>>> I am trying to get all the java versions and paths where it is
>>>>>> located. I got all java_paths in a fact called java_path. Now i need 
>>>>>> those
>>>>>> versions in each custom facts.
>>>>>>
>>>>>> I wrote a code but this not executing .
>>>>>>
>>>>>>
>>>>> Can you provide more details about how it isn't  executing? Is it
>>>>> producing an error? Are any of your facts showing up (java_version_count
>>>>> for example)? Are you sure that you've put the custom fact file in the
>>>>> correct location? Have you followed the guide at
>>>>> https://docs.puppetlabs.com/facter/2.2/custom_facts.html for how to
>>>>> write and use custom facts?
>>>>>
>>>>>
>>>>>> Please help me
>>>>>>
>>>>>> *require 'rexml/document'*
>>>>>> *require 'facter'*
>>>>>>
>>>>>> *Facter.add("java_path") do*
>>>>>> *  setcode do*
>>>>>> *    Facter::Util::Resolution.exec('/home/suppalapati/java.sh')*
>>>>>> *    end*
>>>>>> *end*
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> *logfile = '/home/suppalapati/java.txt'*
>>>>>>
>>>>>> *line_num=0*
>>>>>>
>>>>>> *log = Facter::Util::FileRead.read(logfile)*
>>>>>> *unless log.nil?*
>>>>>> *  log.each_line do |line|*
>>>>>> *    if line.include?('java')*
>>>>>> *       line_num += 1*
>>>>>> *       javaid, val =  %x[ #{log} ]*
>>>>>> *    Facter.add("java_#{javaid}") do*
>>>>>> *      setcode do*
>>>>>> *         val*
>>>>>> *        end*
>>>>>> *       end*
>>>>>> *     end*
>>>>>> *   end*
>>>>>>
>>>>>> * Facter.add("java_version_count") do*
>>>>>> *  setcode do*
>>>>>> *    line_num*
>>>>>> *  end*
>>>>>> * end*
>>>>>> *end*
>>>>>>
>>>>>>
>>>>>> Here is my java.txt file
>>>>>>
>>>>>> */usr/java/jre1.7.0_51/bin/java*
>>>>>> */usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin/java*
>>>>>>
>>>>>> */opt/CLM-Web-Tools/im/linux.gtk.x86_64/jre_6.0.0.sr9_20110208_03/jre/bin/java*
>>>>>>
>>>>>> */opt/CLM-Web-Tools/im/linux.gtk.x86/jre_6.0.0.sr9_20110208_03/jre/bin/java*
>>>>>> */opt/IBM/TeamConcertBuild/jre/bin/java*
>>>>>>
>>>>>> */opt/IBM/InstallationManager/eclipse/jre_6.0.0.sr9_20110208_03/jre/bin/java*
>>>>>>
>>>>>> */opt/IBM/InstallationManager_old/InstallationManager_old/eclipse/jre_6.0.0.sr9_20110208_03/jre/bin/java*
>>>>>> */opt/IBM/TeamConcertBuild_old/jre/bin/java*
>>>>>> */opt/itm/v6.2.2/JRE/lx8266/bin/java*
>>>>>> */var/lib/alternatives/java*
>>>>>> */u01/app/oracle/product/jdk1.7.0_25/jre/bin/java*
>>>>>> */u01/app/oracle/product/jdk1.7.0_25/bin/java*
>>>>>>
>>>>>>
>>>>>> *Please help me*
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Puppet Developers" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>> send an email to [email protected].
>>>>>> To view this discussion on the web visit
>>>>>> https://groups.google.com/d/msgid/puppet-dev/fe7859b3-2eac-4e9c-b495-d4e20dc6dac1%40googlegroups.com
>>>>>> <https://groups.google.com/d/msgid/puppet-dev/fe7859b3-2eac-4e9c-b495-d4e20dc6dac1%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Andrew Parker
>>>>> [email protected]
>>>>> Freenode: zaphod42
>>>>> Twitter: @aparker42
>>>>> Software Developer
>>>>>
>>>>> *Join us at **PuppetConf 2014, **September 20-24 in San Francisco - *
>>>>> www.puppetconf.com
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to a topic in the
>>>>> Google Groups "Puppet Developers" group.
>>>>> To unsubscribe from this topic, visit
>>>>> https://groups.google.com/d/topic/puppet-dev/P6o7RUvvNFo/unsubscribe.
>>>>> To unsubscribe from this group and all its topics, send an email to
>>>>> [email protected].
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/puppet-dev/CANhgQXuHw%2BVWX47Knw6tNeY2A0c0y5P%3DpRo1%2BWC5gK_ipvXh1A%40mail.gmail.com
>>>>> <https://groups.google.com/d/msgid/puppet-dev/CANhgQXuHw%2BVWX47Knw6tNeY2A0c0y5P%3DpRo1%2BWC5gK_ipvXh1A%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Puppet Developers" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/puppet-dev/CAEySWyFiNGwEwGd3PE3wAWomkea8ryCWTYS1-pvXrDHTtgvQ%3Dg%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/puppet-dev/CAEySWyFiNGwEwGd3PE3wAWomkea8ryCWTYS1-pvXrDHTtgvQ%3Dg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
>>>
>>> --
>>> Andrew Parker
>>> [email protected]
>>> Freenode: zaphod42
>>> Twitter: @aparker42
>>> Software Developer
>>>
>>> *Join us at **PuppetConf 2014, **September 20-24 in San Francisco - *
>>> www.puppetconf.com
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Puppet Developers" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/puppet-dev/P6o7RUvvNFo/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/puppet-dev/CANhgQXv9onfSx%3DZQg-08XkiNUb1q%2BUo_xE32%2BgGvZJb_qgEbhg%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/puppet-dev/CANhgQXv9onfSx%3DZQg-08XkiNUb1q%2BUo_xE32%2BgGvZJb_qgEbhg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Puppet Developers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/puppet-dev/CAEySWyG-05AtKBMad1UcNVMnK3z7YqJop%3D5pqSs-ufu9cX%2BjyQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/puppet-dev/CAEySWyG-05AtKBMad1UcNVMnK3z7YqJop%3D5pqSs-ufu9cX%2BjyQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Andrew Parker
> [email protected]
> Freenode: zaphod42
> Twitter: @aparker42
> Software Developer
>
> *Join us at **PuppetConf 2014, **September 20-24 in San Francisco - *
> www.puppetconf.com
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Puppet Developers" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/puppet-dev/P6o7RUvvNFo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-dev/CANhgQXs3oPx0soS2MiHycLJjUhcZHJu96zFxXMtOV90Tsfd4Qw%40mail.gmail.com
> <https://groups.google.com/d/msgid/puppet-dev/CANhgQXs3oPx0soS2MiHycLJjUhcZHJu96zFxXMtOV90Tsfd4Qw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/CAEySWyGobGYqdBPmNFXeuZC83Q-xUuhgLN%3Dk9Pyg25xjGmrUrw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to