获取服务器型号、内存、CPU信息
larry
posted @ 2013年2月17日 21:02
in python
, 2266 阅读
#!/usr/bin/python #2013-02-18 by larry import os import sys import re from collections import Counter def getSN(): s=os.popen('dmidecode -s system-serial-number') n=os.popen('dmidecode -s system-product-name') sn=s.readline().strip() name=n.readline().strip() s.close() if ( len(sn) > 0 ): print "Product Name:",name print "Serial Number:",sn,"\n" else: return -1 def getCPU(): opfile=file('/proc/cpuinfo','r') cpucount=0 phcpucount=0 cpumodel=[] L1=[] for line in opfile.readlines(): i=line.strip('\n') if re.match(r'^processor',i): cpucount=cpucount+1 elif re.match(r'^physical id',i): L1.append(i) elif re.findall('model name',i): cpumodel.append(i.split(':')[1]) else: pass opfile.close() for num in Counter(L1).keys(): phcpucount=phcpucount+1 print "Processor number:",cpucount print "Physical CPU number:",phcpucount print "CPU Model:",cpumodel[0].strip(),"\n" def getMem(): m=os.popen('grep MemTotal /proc/meminfo') max=os.popen('dmidecode -t memory') swm=os.popen('grep SwapTotal /proc/meminfo') L=[] for line in max.readlines(): R1=line.strip("\n") if re.findall('Maximum',R1): sw,se=R1.split(":") L.append(se) max.close() for line1 in swm.readlines(): sw1,sw2,sw3=line1.split() L.append(sw2) for line2 in m.readlines(): m1,m2,m3=line2.split() L.append(m2) print "Memory Total:",int(L[2])/1000/1000,"G" print "Swap Total:",int(L[1])/1024,"M" print "Max support Memory:",L[0] if __name__ == '__main__': print "\x1b[0;34m+++++++++++Device SN+++++++++\x1b[0m" getSN() print "\x1b[0;34m+++++++++++Cpu Info++++++++++\x1b[0m" getCPU() print "\x1b[0;34m+++++++++++Memory +++++++++++\x1b[0m" getMem()
执行脚本结果:
+++++++++++Device SN+++++++++
Product Name: PowerEdge 860
Serial Number: BBNRF2X
+++++++++++Cpu Info++++++++++
Processor number: 4
Physical CPU number: 1
CPU Model: Intel(R) Xeon(R) CPU X3210 @ 2.13GHz
+++++++++++Memory +++++++++++
Memory Total: 4 G
Swap Total: 8189 M
Max support Memory: 8 GB
2013年2月24日 21:13
你这个只是用 python 封装 shell 。
直接用 shell 不好吗?
2024年2月22日 00:55
It was thinking about whether I could utilize this review on my other site, I will connect it back to your site though.Great Thanks
2024年4月19日 20:48
I must say, as a lot as I enjoyed reading what you had to say, I couldnt help but lose interest after a while. Its as if you had a good grasp to the subject matter, but you forgot to include your readers. Perhaps you should think about this from far more than one angle. Or maybe you shouldnt generalise so considerably. Its better if you think about what others may have to say instead of just heading for a gut reaction to the subject. Think about adjusting your own thought process and giving others who may read this the benefit of the doubt.
2024年4月19日 20:49
This article was written by a real thinking writer without a doubt. I agree many of the with the solid points made by the writer. I’ll be back day in and day for further new updates.
2024年4月19日 21:01
You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us to read this
2024年4月19日 21:01
Thank you very much and will look for more postings from you. I feel strongly that love and read more on this topic. If possible, such as gain knowledge, would you mind updating your blog with additional information? It is very useful for me.
2024年4月19日 21:02
I had attempt to advance your own article in to delicius all things considered it’s anything but a predicament utilizing your data destinations would you be able to please reverify the thought. much appreciated again
2024年4月19日 22:17
This is my first time I visit here. I found so many engaging stuff in your blog, particularly its conversation. From the huge loads of remarks on your articles, I surmise I am by all account not the only one having all the recreation here! Keep doing awesome.
2024年4月19日 22:18
Actually an incredible expansion. I have perused this great post. Gratitude for sharing data about it. I truly like that. Much appreciated so part for your assemble.
2024年4月19日 22:19
Celie body wave, deep wave, curly hair, loose wave, wet wavy, kinky straight and more charming sexy hairstyles always keep accompany with you on the way to beauty.
2024年4月19日 22:32
I have been searching the Internet for fun and came upon your website. Fabulous post. Thanks a ton for sharing your knowledge! It is great to see that some people still put in an effort into managing their websites. I’ll be sure to check back again real soon. what a brilliant post I have come across and believe me
2024年4月19日 22:32
I had attempt to advance your own article in to delicius all things considered it’s anything but a predicament utilizing your data destinations would you be able to please reverify the thought. much appreciated again
2024年4月19日 22:32
While i reputation I would in addition train tough created for your incorporate site would like While i embark on a lot of salubrious moreover retained up-to-date chaotic using your situation.
2024年4月19日 22:49
Actually an incredible expansion. I have perused this great post. Gratitude for sharing data about it. I truly like that. Much appreciated so part for your assemble.
2024年4月19日 22:50
Thank you spending some time to talk about the following, I’m boldy a lot and even true love studying more to do with now this topic. However, if future, when you realize know-how, do you ever thoughts bringing up-
2024年4月19日 22:50
You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us to read this
2024年4月19日 22:50
That is the excellent mindset, nonetheless is just not help to make every sence whatsoever preaching about that mather. Virtually any method many thanks in addition to i had endeavor to promote your own article in to delicius nevertheless it is apparently a dilemma using your information sites can you please recheck the idea.
2024年4月19日 22:51
They also need to be good communicators, as they will often need to explain their ideas to clients and contractors. In addition, interior designers should have a good understanding of how different materials and finishes can impact a space.
2024年4月19日 22:51
This is a truly good site post. Not too many people would actually, the way you just did. I am really impressed that there is so much information about this subject that have been uncovered and you’ve done your best, with so much class. If wanted to know more about green smoke reviews, than by all means come in and check our stuff. buy traffic
2024年4月19日 23:13
Thanks for providing recent updates regarding the concern, I look forward to read more.
2024年4月19日 23:14
Actually an incredible expansion. I have perused this great post. Gratitude for sharing data about it. I truly like that. Much appreciated so part for your assemble.
2024年4月19日 23:14
Hmm… As i fully grasp weblogs having a linked problem, all the same as i do not ended pictures web page. As i added in from the piece that can help populars moreover i’ll quite possibly possibly be people specific primer.
2024年4月19日 23:48
Celie body wave, deep wave, curly hair, loose wave, wet wavy, kinky straight and more charming sexy hairstyles always keep accompany with you on the way to beauty.
2024年4月19日 23:48
Nice post! As I see, your writing style is great, without grammatical mistakes. You are doing a great job, so keep it up! Its amazing post thanks for sharing.
2024年4月19日 23:48
That is the excellent mindset, nonetheless is just not help to make every sence whatsoever preaching about that mather. Virtually any method many thanks in addition to i had endeavor to promote your own article in to delicius nevertheless it is apparently a dilemma using your information sites can you please recheck the idea.
2024年4月20日 00:18
Hey all, I recently identified your internet site each and every The major search engines tiny searching for just like sort of educative support furthermore kinds shed light on beholds unbelievably excellent i think.
2024年4月20日 00:19
This is my first time I visit here. I found so many engaging stuff in your blog, particularly its conversation. From the huge loads of remarks on your articles, I surmise I am by all account not the only one having all the recreation here! Keep doing awesome.
2024年4月20日 00:20
I hope this helps almost anyone searching for this type of topic. I think this website is the best for such topics. Good work and quality of article. Major site
2024年4月20日 00:34
whoah this web journal is brilliant i truly like perusing your articles. Keep up the awesome work! You know, numerous individuals are chasing around for this information, you’ll be able offer assistance them enormously.
2024年4月20日 00:34
Celie body wave, deep wave, curly hair, loose wave, wet wavy, kinky straight and more charming sexy hairstyles always keep accompany with you on the way to beauty.
2024年4月20日 00:34
I hope this helps almost anyone searching for this type of topic. I think this website is the best for such topics. Good work and quality of article. Major site
2024年4月20日 01:23
Superb web site, many thanks for finding the time to create these posts, i enjoy looking through all of them!
2024年4月20日 01:24
Great blog here! I wanted to thank you for this very good read post! I definitely enjoyed every bit of it. I have got you book-marked. Thank you for sharing.
2024年4月20日 01:24
Great blog here! I wanted to thank you for this very good read post! I definitely enjoyed every bit of it. I have got you book-marked. Thank you for sharing.
2024年4月20日 03:00
I reckon your current visitors may perhaps want way more information like this keep up the excellent work.
2024年4月20日 03:01
I want to remark on some things on your blog, the site style is perfect and the articles are really excellent. Good job, cheers. See this
2024年4月20日 03:02
I have been searching the Internet for fun and came upon your website. Fabulous post. Thanks a ton for sharing your knowledge! It is great to see that some people still put in an effort into managing their websites. I’ll be sure to check back again real soon. what a brilliant post I have come across and believe me