Revision: 37870
Updated Code
at December 19, 2010 18:23 by Affix
Updated Code
#!/usr/bin/perl
#
# Author : Keiran "Affix" Smith <Affix_at_Affix_dot_me>
# Website: http://keiran-smith.net
# Description :
# Parse the output of the linux uptime command into easy to understand
# readable text x Days y Hours z Minutes
# UPDATES :
# - December 19th 2010
# + Fixed a bug regarding minutes
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# Get and Parse System Uptime
@uptime1 = split(/\,/, `uptime`);
@uptime2 = split(/ /, $uptime1[0]);
@uptime2 = split(/\:/, $uptime2[3]);
@hrmin = split(/ /, $uptime1[0]);
@days = split(/ /, $uptime1[0]);
$days[3] =~ s/[0-9][0-9]:[0-9][0-9]/0/;
if($days[3] < 1)
{
@hrmins = split(/\:/, $hrmin[4]);
$uptime = $hrmins[0] . " Hours " . $hrmins[1] . " Minutes";
}
else
{
$uptime1[1] =~ s/ //;
@hrmins = split(/\:/, $uptime1[1]);
@hours = split(/ /, $hrmins[0]);
if($hours[2] == 'users')
{
$uptime = $days[3] . " Minutes";
}
else
{
$uptime = $days[3] . " Days " . $hrmins[0] . " Hours " . $hrmins[1] . " Minutes";
}
}
print $uptime;
Revision: 37869
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at December 18, 2010 20:59 by Affix
Initial Code
#!/usr/bin/perl
#
# Author : Keiran "Affix" Smith <Affix_at_Affix_dot_me>
# Website: http://keiran-smith.net
# Description :
# Parse the output of the linux uptime command into easy to understand
# readable text x Days y Hours z Minutes
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
@uptime1 = split(/\,/, `uptime`);
@uptime2 = split(/ /, $uptime1[0]);
@uptime2 = split(/\:/, $uptime2[3]);
@hrmin = split(/ /, $uptime1[0]);
@days = split(/ /, $uptime1[0]);
$days[3] =~ s/[0-9][0-9]:[0-9][0-9]/0/;
if($days[3] < 1)
{
@hrmins = split(/\:/, $hrmin[4]);
$uptime = $hrmins[0] . " Hours " . $hrmins[1] . " Minutes";
}
else
{
$uptime1[1] =~ s/ //;
@hrmins = split(/\:/, $uptime1[1]);
$uptime = $days[3] . " Days " . $hrmins[0] . " Hours " . $hrmins[1] . " Minutes";
}
print $uptime;
Initial URL
http://affix.me
Initial Description
Initial Title
Parse Linux Uptime
Initial Tags
Initial Language
Perl