Mac Book Python writes the first fabric test sample

Source: Internet
Author: User

Recently learned the next fabric, python similar features of the tool many, the reason for the choice of fabric, the first is that it is not much syntax, easy to get started, the second is its syntax logic, scripting more in line with the Python grammar habits, not easy to run biased


Fabric is a Python (2.5-2.7) library and command-line tool for streamlining the use of SSH for application deployment or S Ystems administration tasks.

This thing in bulk processing some remote commands, tasks, more convenient, a little bit python (he is a Python library, and the general task is written in the form of Pyton function) can be used, relatively simple.


It's easy to set up:

pip install fabric


Official website: http://www.fabfile.org



Write a test example with the following code:



#!/usr/bin/env python

#-*-Coding:utf-8-*-

"""

Created on Thu Jan 12 20:09:50 2017

@author: Fuyuan

"""

#!/usr/bin/env python

#-*-Coding:utf-8-*

#fabfile. py

From FABRIC.API Import *

Env.user = ' Tomcat '

env.hosts = [' 192.168.200.32 ']

Env.password = ' to****2015 '

def download ():

Local (' Rm-rf/tmp/newer ')

Local (' Mkdir/tmp/newer ')

Def pack ():

With LCD ('/tmp/'):

Local (' Tar czvf newer.tar.gz./newer ')

def display ():

Run (' rm-rf/home/tomcat/tmp ')

Run (' mkdir/home/tomcat/tmp ')

Put ('/tmp/newer.tar.gz ', '/home/tomcat/tmp ')

With CD ('/home/tomcat/tmp '):

Run (' Tar xvf newer.tar.gz ')

Run (' ls-l ')

def go ():

Download ()

Pack ()

Display ()

#fab-F spider-fabric1.py Go



Because SSH-based, the effect of course is good, simple, but also found a problem, directly installed locally, but can not be imported into the pycharm, so that the use of other editors to test the first, and then continue to figure out how to directly pycharm reference to the local installation package, after all, Pycharm used to;


This article is from "Good Sir 2020" blog, please make sure to keep this source http://fuyuan2016.blog.51cto.com/8678344/1891603

Mac Book Python writes the first fabric test sample

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.