What applications does Python have in Linux system O & M?

Source: Internet
Author: User
Tags saltstack
After learning python for a while, I feel that my learning posture is not correct. I always feel that python is more inclined to web development than shell and perl. However, the O & M management for linux is weak. Aside from the O & M tools developed using python such as fabric. What can I do with python in daily O & M? What is more convenient or efficient than shell scripts? Now, I have only used python to write some log analysis scripts and simple scripts that extract uid from the page to generate links and test the playback and other actions. After learning python for a while, I feel that my learning posture is not correct. I always feel that python is more inclined to web development than shell and perl. However, the O & M management for linux is weak.
Aside from the O & M tools developed using python such as fabric. What can I do with python in daily O & M? What is more convenient or efficient than shell scripts?
Now, I have only used python to write some log analysis scripts and simple scripts that extract uid from the page to generate links and test the playback and other actions.
Others don't know what to do.
I would like to ask more advice from my predecessors. It would be better if there are some specific instances.

The same question is also raised on v2ex http://www.v2ex.com/t/75193

Thanks for your reply: I prefer "System Management" to describe "O & M. O & M sounds like a partial task. The advantages of python in system management lies in its powerful development capabilities and complete tool chain. Python has powerful engineering development capabilities, far better than various shell and perl. Easy to read and write, with both object-oriented and functional styles, as well as good meta programming capabilities. By systematically combining various management tools, we conduct secondary development on the above tools to form a unified server management system.
Ruby similar to python is also suitable for compiling system management software, but it is much worse than python in related libraries and tools.

For example, a good man, proficient in bash, python, perl, ruby, writes hundreds of Single-function scripts (in any language) at work for daily operations, it covers monitoring, deployment, network configuration, log analysis, security detection, and many other aspects. What he did was just an operation, and he did not do well in system management. A lot of scripts only limit the "operation" behavior. Writing more scripts cannot be converted into valuable assets of the company in system management.

Making the system easy to manage is a project. Only automated management tools such as puppet (ruby) and saltstack (python) can fully describe the entire system and integrate all aspects of system management into a unified system, rather than a bunch of scripts.
Python is very rich in server management tools. Configuration Management (saltstack) Batch execution (fabric, saltstack) Monitoring (Zenoss, nagios plug-in) virtualization Management (python-libvirt) process management (supervisor) cloud computing (openstack )...... most system C libraries are bound to python.
The process must be incorporated into the system management system, written as a program, and become part of the system. Instead of reusing all types of independent scripts.
With the advent of the cloud computing era, small and medium enterprises do not need O & M. Large companies, O & M without engineering development capabilities, are not competitive. No more perl now? Thank you. You are right. Python is weaker than Perl and Bash in daily O & M. Python is also much more troublesome for Web development than PHP. I personally think Python is more like Java and is not suitable for comparison with Perl/Bash.
My personal common O & M tools are mainly Bash, and Python is mainly used for algorithm calculation. Because my daily maintenance tasks focus on file system maintenance, the comparison language should be combined with the scenario.

Most of the application requirements can be fulfilled in all languages, but the difficulty is different. The language selection depends on the developer's proficiency and complexity of the requirements.
If you only need "grep", Bash is the easiest way to execute grep. If it is a little complex, awk is used. If it is more complex, perl is used. It is effort-consuming to use a more common language.
If it is a matrix computing requirement, the perl array can throw you, And the bash pipeline can throw the machine.

My opinion below will be controversial (especially PHPer). I tend to divide advanced languages into three categories:
1) underlying C/C ++
This allows you to write the operating system and operate the hardware. All problems can be solved, but most Internet projects should not be used.
2) Neutral Java/Python/Ruby/. NET Series
This is the main language for project development, balancing development efficiency and execution efficiency. There are no obvious highlights and no obvious shortcomings.
3) expertise in PHP/Bash/Perl
In some specific fields, you should select these special languages. As the demand becomes more comprehensive and the short board of the language becomes more and more widely used, the spread of the language should be controlled. If fabric and func are used ...... My current feeling is that any one-time script that is not "burning after reading", especially the script that may need to be modified and adjusted in the future, should replace Bash with Python. Think about "I have a bunch of Hosts. I want to separate them ......" This type of array operation. Think about replacing the Great bash string. Think about quoting. Bash perfectly inherits the "Write-only" attribute of Perl.

Non-O & M personnel, there is a pile of small machines in their labs.

@ Feng Weigang high execution efficiency Bash? Is it a joke about the "software engineer" in your signature?

Python_vs_bash_benchmark.zip


  • The Python program in this example is about 6 times faster than the BASH program.
  • Python is a little slower in this example as it is only 3 times faster than BASH
  • Python is roughly 5.5 times faster than BASH in this test.
  • With Python lists being 29 times faster and Python dictionaries being 23.7 times faster using BASH forany kind of sequential data manipulation is unacceptable (unless it is very small amounts of data ).
  • Since in this simple function calling program Python is 11.77 times faster than BASH, BASH is thereforerestricted to linear program whereas Python is only 48% (verses the 476% of BASH) slower than the non function calling program and for that reason is a very good structured programming language (keep inmind that 10000 function CILS were made in both programs ).


In fact, you don't need to watch any tests at all. A large number of operations depend on inter-process communication without JIT and intermediate code optimization. Bash that supports a complex data structure is approximately equal to zero. It must be compared with Python in terms of functions and efficiency, is to execute. /xxx. py or simply write it as a C program. Bash is a good practice, but python has the advantages of many web frameworks for visual O & M processes and results.
This is incomparable in terms of user friendliness.
How many O & M scripts do you write in a month? How many O & M scripts are maintained? If there are less than 10 of them, there is no difference between bash and python.

P.S. Python tends to be web? So honored... I thought I would say PHP... No. py sa is not a qualified sa. It once managed two hundred servers with secondary CT. Now it is too good.

Just two days ago, miller's kernel Nic interrupt patch script was still in salt with less than 10 lines of py. We can see that py is concise.

O & M automation configuration is still dominated by py and ruby. If fabric or even saltstack and ansible O & M tools are put aside, it is difficult to reflect the strength of python.
Read the "Python UNIX and Linux System Management Guide", Try it out.

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.