用python写的获取linux本机信息,包括kernel、IP、Memory、Disk信息。######################################################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". #######################################################翻译:本程序是用来获取linux本机信息的你可以输入“kernel”,“ip”,“memory”,“disk”关键字获取响应的参数信息也可以输入“all”,查看所有参数。程序内容如下:
- #!/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""").read().strip("
")
- ip = os.popen("""/sbin/ifconfig | grep "inet addr"|awk "{print $2}"|head -1 |cut -d ":" -f 2""").read().strip("
")
- memory = os.popen("""free -m | head -2""").read().strip("
")
- disk = os.popen("""df -hT""").read().strip("
")
- 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("
")
- a = str(raw_input("Please input to query parameter:"))
- if a == "kernel":
- print "Kernel Version:",kernel_version
- elif a == "ip":
- print "Local IP:",ip
- elif a == "memory":
- print "Local Memory:" + ("
") + memory
- elif a == "disk":
- print "Local Disk:" + ("
") + disk
- elif a == "all":
- print "Kernel Version:",kernel_version
- print "Local IP:",ip
- print "Local Memory:" + ("
") + memory
- print "Local Disk:" + ("
") + disk
- else:
- print "Didnt"t you want to query parameter."
最近在学习python,所以就各种找需求去练习,写的也简单,各种堆命令,有什么不对的地方或者好的建议,还请指出。