Skip to content

Instantly share code, notes, and snippets.

@nb5p
Created April 13, 2019 05:41
Show Gist options
  • Select an option

  • Save nb5p/157b944cf40a5e408205313add184d96 to your computer and use it in GitHub Desktop.

Select an option

Save nb5p/157b944cf40a5e408205313add184d96 to your computer and use it in GitHub Desktop.
Get system info.
from subprocess import Popen, PIPE
def hostname():
hostname = Popen(["hostname"], stdout=PIPE)
hostname = hostname.stdout.read()
return hostname
def osversion():
with open("/etc/issue") as f:
osversion = f.read()
return osversion
def oscoreversion():
oscoreversion = Popen(["uname", "-r"], stdout=PIPE)
oscoreversion = oscoreversion.stdout.read()
return oscoreversion
def cpuinfo():
corenumber = []
with open("/proc/cpuinfo") as cpuinfo:
for i in cpuinfo:
if i.startswith("processor"):
corenumber.append(i)
if i.startswith("model name"):
cpumode = i.split(":")[1]
return corenumber, cpumode
def meminfo():
with open("/proc/meminfo") as meminfo:
for i in meminfo:
if i.startswith("MemTotal"):
totalmem = i.split(":")[1]
return totalmem
if __name__ == '__main__':
hostname()
osversion()
oscoreversion()
cpuinfo()
meninfo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment