Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support  

 FAQFAQ   SearchSearch   MemberlistMemberlist    RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    


Error in ./scripts/unix_memory.pl

 
Post new topic   Reply to topic    Cacti Forum Index -> Scripts and Templates
Author Message
torstentfk
Cacti User


Joined: 05 Apr 2005
Posts: 181
Location: Munich, Germany

PostPosted: Fri Sep 26, 2008 4:13 am    Post subject: Error in ./scripts/unix_memory.pl Reply with quote

Hi,

new-code:
Code:

#!/usr/bin/perl

open(PROCESS, "cat /proc/meminfo | grep  $ARGV[0] |");
foreach (<PROCESS>) {
        if ($_ =~ /($ARGV[0].*\s)(.*[0-9])( kB)/) {
                print $2;
                close(PROCESS); 
                exit();
        }
}
close(PROCESS);


Inside the if-clause the close() and exit()-statement were missing:

Code:
$# cat /proc/meminfo
MemTotal:      2076980 kB
MemFree:       1539736 kB
Buffers:        143224 kB
Cached:         250748 kB
SwapCached:          0 kB
Active:         330108 kB
Inactive:       150644 kB

If there there are more lines matching the grep-string the script would concat all numbers at the output.
I haved call the script with "Cached" an got 2507480 KB. The last zero in the output is fetched from the next line "SwapCached"....

Torsten
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Cacti Forum Index -> Scripts and Templates All times are GMT - 5 Hours
Page 1 of 1

 



Powered by phpBB © 2001, 2005 phpBB Group