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'))
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章