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