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)

On 25/11/14 17:38, Spriya wrote:
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_path 1.7.0_65/u01/java/jdk1.7.0_65/bin/java java_u01_weblogic_foundversion1u01_1_path 1.7.0_72/u01/java/jdk1.7.0_72/jre/bin/java java_u01_weblogic_foundversion5u01_5_path 1.7.0_72/u01/java/jdk1.7.0_72/bin/java java_u01_weblogic_foundversion9u01_9_path 1.7.0_65/u01/java/jdk1.7.0_65/jre/bin/java
java_u01_weblogic_foundversion_count    16


The count should be 4 but it is giving me 16 locations. Can anyone help me?
--
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+unsubscr...@googlegroups.com <mailto:puppet-users+unsubscr...@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 <https://groups.google.com/d/msgid/puppet-users/7ef2d1ee-7c32-4f55-b397-a06c5847c0f6%40googlegroups.com?utm_medium=email&utm_source=footer>.
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
_________________________________________________________

Next 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 Training | 
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

--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/5474D804.8090409%40open-future.be.
For more options, visit https://groups.google.com/d/optout.

Reply via email to