Perlfunc: get_uptime()

Simple code to get the current uptime in days.

sub get_uptime {
   open(FILE,'/proc/uptime');
   my $line = <FILE>;
   close FILE;

   # The first value is seconds of uptime, not sure about the second
   my ($seconds,$foo) = split(/\s+/,$line);

   # Convert seconds to days
   my $ret = int($seconds / (3600 * 24));

   return $ret;
}
Leave A Reply
All content licensed under the Creative Commons License