Python SH Library Learning

Source: Internet
Author: User
Tags glob percona

The official documentation has a phrase "allows you to call any program" and:

Helps you write shell scripts In python by giving you the good features of bash first sentence to help you easily call your own program in Python, the second sentence gives you the opportunity and Shell This local tyrants make Friends  ㈠ call System program [Python]  >>> import sh  >>> print (sh.ls ('/home/mysql '))  cdio_bak.sql  mysql-5.5.16.tar.gz  mm         percona-xtrabackup-2.1.4-656-linux-i686.tar.gz  mysql         percona-xtrabackup-2.1.4-linux-i686  mysql-5.5.16  startmysql.sh   ㈡ calls its own program [Python]  > >> Import sh  >>> r=sh. Command ('/root/dd.py ')  >>> R ()  hello,dba   ㈢bake commands parameters [Python]  >>> Import sh  >>> du=sh.du.bake ('-SHC ')  >>> print (Du ('/home/mysql '))  1.1g    /home/mysql  1.1g     Total   ㈣glob listing files [python]  >>> import sh  >> > List=sh.glob ('/root/mm/* ')  >>> Print List  ['/root/mm/backup ', '/root/Mm/usplash ', '/root/mm/awn ', '/root/mm/wallpapers ', '/root/mm/grub ', '/root/mm/mozilla ']   ㈤ pipeline [python]  >>> Print (Sh.sort (Sh.du (Sh.glob (' * '), '-SHC '), '-rn ')  712k     distribute-0.6.49.tar.gz  672k    setuptools-1.1.5.tar.gz  548k    get-pip.py     Pipeline is ordered, by default from the inside out, but what if parallelism is required? Add a _piped=true [python]  >>> for line in sh.tr (Sh.tail ("-F", "/home/mysql/mysql/log/alert.log", _ piped=true), "[: Upper:]", "[: Lower:]", _iter=true): &nbsp, ....   Print line  ..   innodb: Doublewrite Buffer not found:creating new    innodb:doublewrite buffer created    innodb : 127 rollback Segment (s) active.    innodb:creating FOREIGN KEY constraint system tables    innodb:foreign key constraint System Tables created 

Python SH Library learning

Related Article

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.