Skip to content

Instantly share code, notes, and snippets.

@carlkibler
Created June 10, 2011 22:01
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save carlkibler/1019870 to your computer and use it in GitHub Desktop.
Save carlkibler/1019870 to your computer and use it in GitHub Desktop.
Retrieve system uptime with Python
import subprocess
def uptime():
raw = subprocess.check_output('uptime').replace(',','')
days = int(raw.split()[2])
if 'min' in raw:
hours = 0
minutes = int(raw[4])
else:
hours, minutes = map(int,raw.split()[4].split(':'))
totalsecs = days*24*60*60 + hours*60*60 + minutes*60
return totalsecs
print 'System uptime of %d seconds' % (uptime())
@globoblanco
Copy link

It would be nice if the code you post would actually work.

@zknight137
Copy link

It would be nice if the code you post would actually work.

Works with python2, pleb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment