Write in Python to get Linux native information, including kernel, IP, Memory, disk information.
################################################################################
#Information on this program are used to get the Linux native. #
#You can enter the "kernel", "IP", "Memory", "disk" keyword to get the results,#
#you can also enter "all". #
###############################################################################
Translation: This program is used to obtain the Linux native information
You can enter the "kernel", "IP", "Memory", "disk" keyword to get the parameter information of the response
You can also enter "all" to view all parameters.
The contents of the program are as follows:
#!/usr/bin/env python #-*-coding:utf-8-*-#2012/12/12 by Songshoujiong #Email: linuxsong49@163.com Import OS kernel_version = Os.popen ('/bin/uname-a | awk \ ' {print $1,$3}\ '). Read (). strip (' \ n ') IP = os.po Pen ('/sbin/ifconfig | grep ' inet addr ' |awk ' {print $} ' |head-1 |cut-d ': ' F 2 '). Read (). strip (' \ n ') memory = OS. Popen (' free-m | head-2 '). Read (). strip (' \ n ') disk = Os.popen (' ' df-ht '). Read (). strip (' \ n ') print "################################################################################ #Information on" This program is used to get the Linux native. # #You can enter the ' kernel ', ' IP ', ' memory ', ' disk ' keyword to get the results,# #you can also enter ' all '. #
################################################################## ############# '. Strip (' \ n ') a = str (raw_input (' please input to query parameter: ')
If a = = ' kernel ': print ' kernel Version: ', kernel_version elif a = = ' IP ': print ' local IP: ', I P elif A = = ' Memory ': print "local Memory:" + (' \ n ') + memory elif a = ' disk ': print ' Loc Al disk: "+ (' \ n ') + disk elif a =" all ": print" Kernel Version: ", kernel_version print" local
IP: ", IP print" local Memory: "+ (' \ n ') + Memory print" local Disk: "+ (' \ n ') + Disk else: print "didnt ' t you want to query parameter."