
charlesD
Novice
Apr 13, 2009, 9:57 AM
Post #7 of 7
(1518 views)
|
|
Re: [KevinR] regexp for uptime
[In reply to]
|
Can't Post
|
|
It means one of the variables you are printing has no value, here is a very simplified example: use warnings; $foo = $1; print $foo; $foo is assigned the value of $1, but since $1 has no value $foo also has no value (uninitialized) and when you try and print an uninitialzed variable the warnings pragma (or the warnings switch on the shebang line) returns the warning you are getting. Basically its letting you know there is something you should check to make sure it will not cause a bigger problem somewhere down the line. You can avoid the warnings by assigning default values: use warnings; $foo = $1 || 'foo'; print $foo; Thats just one example of how it could be done. OK, I understand. So much to learn. :-) I have actually completed my script that this is all releated to, using whatever workarounds I could find. #!/usr/bin/perl -w print "Content-type: text/plain","\n\n"; $uptime = `/usr/bin/uptime`; $sysdate = `date "+%A, %B %d %Y"`; $systime = `date +"%H:%M"`; ($load_average) = $uptime =~ /averages: ([^ ]{4})/; $ps = `ps ax | wc -l | sed 's/^[ \t]*//'`; print "The current system date is: ", $sysdate; print "The current system time is: ", $systime; open(UPTXT, "up.txt") || die "Cannot Open: $!"; while (<UPTXT>) { chomp; print "The system was last booted ", $_, "\n"; } print "The current number of running processes is ", $ps; print "The current load average on the system is: ", $load_average, "\n"; exit (0); Ther is a cron job that run when the server is booted that does "echo `date` > up.txt" which is the file I read as UPTXT. You can view the actual web page here: http://bubbabbq.homeunix.net/up_cgi.shtml -- Thanks, Charles Using Perl since 4/12/09 perl 5.8.9, FreeBSD 6.4-STABLE http://bubbabbq.homeunix.net
|