Advertisement
Guest User

Python show *nix uptime

a guest
Jan 4th, 2011
460
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. '''
  4. Show system uptime in *nix platforms
  5. '''
  6.  
  7. __version__ = '0.0.1'
  8. __author__ = {'Mauro Baraldi': 'mauro.baraldi@gmail.com'}
  9.  
  10. import os
  11. from datetime import datetime
  12.  
  13. def uptime():
  14.     with open( "/proc/uptime" ) as ut:
  15.         uptime = datetime.fromtimestamp(float(ut.read().split()[0]))
  16.     return "The system uptime for %i days, %i hours, %i minutes, %i seconds" % (uptime.day, uptime.hour, uptime.minute, uptime.second)
  17.  
  18. if __name__ == "__main __":
  19.     print uptime()
Advertisement
RAW Paste Data Copied
Advertisement