[Lxc-users] uptime

Papp Tamas tompos at martos.bme.hu
Mon May 14 09:57:44 UTC 2012


On 05/04/2012 09:04 AM, Ulli Horlacher wrote:
> On Fri 2012-05-04 (00:05), Samuel Maftoul wrote:
>
>> Maybe, the uptime of container's init process will show you uptime of the
>> container (so is accessible from within the container).
> init does not provide its start time
>
> I have now written a special uptime command to be placed in the containers
> PATH:
>
> #!/usr/bin/perl -w
>
> $uptime = `/usr/bin/uptime`;
> @s = lstat '/dev/pts' or die $uptime;
> $s = time - $s[10];
> if ($s>172800) {
>    $d = int($s/86400);
>    $uptime =~ s/up .*?,/up $d days,/;
> } else {
>    $h = int($s/3600);
>    $m = int(($s-$h*3600)/60);
>    $uptime =~ s/up .*?,/sprintf("up %02d:%02d,",$h,$m)/e;
> }
> print $uptime;

Does this work for you?
Not for me.

Thanks,
tamas





More information about the lxc-users mailing list