Skip to content

Commit

Permalink
Merge pull request #77 from arnaudbey/master
Browse files Browse the repository at this point in the history
format uptime to day hour min
  • Loading branch information
tariqbuilds committed Feb 5, 2014
2 parents 84864dc + da700cf commit 50b60e3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ <h3>General Info</h3>
<br>
<div style="text-align:center;">
<b>OS:</b> <span class="" id="os-info"></span><br>
<b>Uptime:</b> <span class="odometer" id="os-uptime"></span> Hours<br>
<b>Uptime:</b> <span id="os-uptime"></span><br>
<b>Hostname:</b> <span class="" id="os-hostname"></span><br>
<br><br>
</div>
Expand Down
23 changes: 22 additions & 1 deletion sh/uptime.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
<?php

header('Content-Type: application/json; charset=UTF-8');
echo json_encode((int) (shell_exec('/bin/cat /proc/uptime')/(60*60)));

$totalSeconds = shell_exec("/usr/bin/cut -d. -f1 /proc/uptime");
$totalMin = $totalSeconds / 60;
$totalHours = $totalMin / 60;

$days = floor($totalHours / 24);
$hours = floor($totalHours - ($days * 24));
$min = floor($totalMin - ($days * 60 * 24) - ($hours * 60));

if ($days != 0) {
$formatUptime = "$days days ";
}

if ($hours != 0) {
$formatUptime .= "$hours hours ";
}

if ($min != 0) {
$formatUptime .= "$min minutes";
}

echo json_encode($formatUptime);

0 comments on commit 50b60e3

Please sign in to comment.