my line count is giving me wrong values in puppet facts

24 views
Skip to first unread message

Spriya

unread,
Nov 25, 2014, 11:38:29 AM11/25/14
to puppet...@googlegroups.com
Hi,

when i am trying to count the lines in how many  locations the java is. It is giving me wrong count. 

Here is my code:
require 'facter'
require 'facter/util/file_read'

logfile = "/home/weblogic/javaapp.txt"
java_count = 0
if File.exist? '/home/weblogic/javaapp.txt'

log = Facter::Util::FileRead.read(logfile)
unless log.nil?
log.each_line do |line|
   val = line.split(' ')
    java_path = val.grep(%r!/java!).join(',')
    java_version = val.grep(%r!/java!).map{ |s| s[/\d+\.[a-z\d._-]+/] }.join(',')
    java_count += 1
Facter.add("java_u01_weblogic_foundversion#{java_count}u01_#{java_count}_path") do
 setcode do
   java_version + java_path
end
end
end
end
end

Facter.add("java_u01_weblogic_foundversion_count") do
    setcode do
      java_count
     end
    end


Here is my txt file
/u01/java/jdk1.7.0_72/jre/bin/java
java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)
/u01/java/jdk1.7.0_72/bin/java
java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)
/u01/java/jdk1.7.0_65/jre/bin/java
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
/u01/java/jdk1.7.0_65/bin/java
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

Here is my facts

java_u01_weblogic_foundversion13u01_13_path1.7.0_65/u01/java/jdk1.7.0_65/bin/java
java_u01_weblogic_foundversion1u01_1_path1.7.0_72/u01/java/jdk1.7.0_72/jre/bin/java
java_u01_weblogic_foundversion5u01_5_path1.7.0_72/u01/java/jdk1.7.0_72/bin/java
java_u01_weblogic_foundversion9u01_9_path1.7.0_65/u01/java/jdk1.7.0_65/jre/bin/java
java_u01_weblogic_foundversion_count16

The count should be 4 but it is giving me 16 locations. Can anyone help me?

Johan De Wit

unread,
Nov 25, 2014, 2:27:23 PM11/25/14
to puppet...@googlegroups.com
I count 16 lines in your txt file, so the fact is working as you coded it.  You should increment only if you find another version in you file, and there are only 4 in the file  (or something else)
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/7ef2d1ee-7c32-4f55-b397-a06c5847c0f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


-- 
Johan De Wit

Open Source Consultant

Red Hat Certified Engineer              (805008667232363)
Puppet Certified Professional 2013/2014 (PCP0000006)
_________________________________________________________
 
Open-Future                 Phone     +32 (0)2/255 70 70
Zavelstraat 72              Fax       +32 (0)2/255 70 71
3071 KORTENBERG             Mobile    +32 (0)474/42 40 73
BELGIUM                     http://www.open-future.be
_________________________________________________________
 

Upcoming Events:

Puppet Introduction Course | http://www.open-future.be/puppet-introduction-course-10th-november

Puppet Fundamentals Training | http://www.open-future.be/puppet-fundamentals-training-12-till-14th-november

Zabbix Certified Specialist | http://www.open-future.be/zabbix-certified-specialist-training-17-till-19th-november

Zabbix Certified Professional | http://www.open-future.be/zabbix-certified-professional-training-20-till-21st-november

Subscribe to our newsletter: http://eepurl.com/BUG8H


Reply all
Reply to author
Forward
0 new messages