dharmit / tinyutils

Small utils to print Linux system info in a prettier format
MIT License
4 stars 8 forks source link

cpuutils.py #19

Closed rohansharma777 closed 9 years ago

rohansharma777 commented 9 years ago

import subprocess

def cpu(): output, err = \ subprocess.Popen(['top', '-bn1', ' |', ' grep', ' " Cpu(s)"', ' |', ' \ ', 'sed', ' "s/.,', ' *([0-9.])%', 'id./\1/"', ' |', ' \ ' 'awk', ' \'{print 100 - $1"%"}\'\''], stdout=subprocess.PIPE).communicate() cpu_usage = output print(cpu_usage)