-
-
Save algotrader-dotcom/921857cd9d7a247f0f416d84107928c9 to your computer and use it in GitHub Desktop.
Retrieve system uptime with Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment