fabric常用API

#coding:utf8
from fabric.api import *
from fabric.colors import *
from fabric.contrib.console import confirm

env.hosts = ['192.168.1.112','chang']
env.user = 'root'
env.password = '1'
env.port = 22

@task
def local_cmd():
    local('ls -la')
    with lcd('/mnt'):
        local('ls -l')



@task
def remote_cmd():
    #run('free -m')
    #run('cat /etc/passwd')
    with cd('/mnt'):
        run('ls')

#上传文件
@task
def put():
    put('./a','/mnt/abc')
    run('ls /mnt/abc')

#下载文件
@task
def get1():
    get('/mnt/abc','./abc.txt')
    local('ls -l')


@task
def confirm1():
    content = prompt('请输入字符穿:')
    print(content)
    confirm('请确认[Y/N]?')


@task
def show_color():
    print(white('hello world'))
    print(blue('blue'))
    print(red('red'))
    print(yellow('yellow'))
    print(magenta('magenta'))

你可能感兴趣的:(fabric)