Obtain information about the linux host, including kernel, IP, Memory, and Disk, written in python.
######################################## ########################################
# 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 ".#
######################################## #######################################
This program is used to obtain information about the linux host.
You can enter the "kernel", "ip", "memory", and "disk" keywords to obtain response parameter information.
You can also enter "all" to view all parameters.
The program content is 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.popen('''/sbin/ifconfig | grep 'inet addr'|awk '{print $2}'|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:",ip
- elif a == 'memory':
- print "Local Memory:" + ('\n') + memory
- elif a == 'disk':
- print "Local 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."
I have been studying python recently, so I want to find various requirements to practice. It is also simple to write, and there are various heap commands. What are wrong or good suggestions? Please also point out.
This article comes from "My future is not a dream ." Blog, please be sure to keep this source http://song49.blog.51cto.com/4480450/1086861