| |||||||||||
| |||||||||||
change a perl prog Posted by mike21 (mike21), 22 November 2004 hello ,this is what i have in /proc/meminfo (linux machine) : total: used: free: shared: buffers: cached: Mem: 261390336 210886656 50503680 0 56795136 84643840 Swap: 536731648 0 536731648 MemTotal: 255264 kB MemFree: 49320 kB MemShared: 0 kB Buffers: 55464 kB Cached: 82660 kB SwapCached: 0 kB Active: 131360 kB ActiveAnon: 5940 kB ActiveCache: 125420 kB I write a prog in perl but it doesn't work because i'd like to read those 3 numbers : 261390336 210886656 50503680 of the Mem.... and my prog , here : #! /usr/bin/perl -w use strict ; # Recuperation du contenu du fichier open LOAD, "</proc/meminfo" or die "Impossible d'acceder a memoire"; my($meminfo)=<LOAD>; chomp $meminfo; close LOAD; # affiche les valeur de meminfo my @charges = split (" ", $meminfo); # Traitement print "taille de ma memoire $charges[0]\n" ; print "taille de la memoire utiliser $charges[1]\n" ; print "taille de la memoire libre $charges[2]\n" ; print "\n" ; give me that: taille de ma memoire total: taille de la memoire utiliser used: taille de la memoire libre free: i would like to display Mem line in place of total, used, free... thanx very much regards, mike Posted by John_Moylan (jfp), 22 November 2004 Try this:Code:
I have noted any changes I made in the code Posted by John_Moylan (jfp), 22 November 2004 Just to update what was happening in your code:Code:
Code:
If you really wanted *all* the output you would have to undefine a special Perl variable by adding "undef($/);" to your code before your read your file. What does $/ do? $/ is the input record separator, this is set by default to 'newline, and thats exactly what it did for you, only gave you everything up to the newline. By undefining the variable it will have nothing to separate on and therefore gives you everything. : Start contradict mode Personally I avoid slurping a complete file cos it can take up a fair chunck of memory, I also use it a lot! ![]() : End contradict mode In this example I think getting an array of lines (as my code shows) is more elegant than slurping. I'm sure others will correct me here if I'm wrong. jfp Posted by mike21 (mike21), 23 November 2004 hello,i just would like to know how can i write this code in PERL : if charge > seuil2 then Afficher (critical) else if charge > seuil1 then Afficher (warning) endif endif thanx in advance regards Posted by admin (Graham Ellis), 23 November 2004 Something likeCode:
but it depends on what was a variable, what was a constant and what was a subroutine name in your original code. Posted by mike21 (mike21), 24 November 2004 thanx ,in fact my question is I would like to know how can i read the names of the process which running and and how can i display it on an array? then i would like to do a comparaison , if the process X doesn't run , then print "ALERT !!" I show you teh beginnig of my prog but... ![]() #! /usr/bin/perl -w use strict ; open(PS_F, "ps -A | grep man |"); while (<PS_F>) { ($PID,$TTY,$TIME,$CMD) = split; } close(PS_F); cheers all Posted by admin (Graham Ellis), 24 November 2004 Je pense que votre francais est plus belle que votre anglais? C'est un peu difficille point moi a comprerendre votre question ![]() if you add push @processes,$CMD; at the end of your loop, then you'll have a list of all the processes running. If you add $gotit = i if ($CMD =~ /processname/); at the end of your loop, you'll then know if the process that you are interested in is being run once your loop has exited by checking the $gotit variable. This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |