Get the Linux native information perfectly in Python

Source: Internet
Author: User
Tags in python linux

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."

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.