[Lxc-users] What should 'uptime' say inside an lxc container?

Jäkel, Guido G.Jaekel at dnb.de
Tue Sep 11 06:39:52 UTC 2012


Dear Dan,

As a workaround you may use the  following perl script written by Ullrich Horlacher. It also demonstrates the basic idea where to get a containers uptime from. Here he use a well known file, but I think one may also use the information related to the containers init process.

	lxc-uptime:
	#!/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;                  


with greetings

Guido




More information about the lxc-users mailing list