Back to Fabric


1. Run a shell command on a remote host*args, **kwargs)

# Run Silently, specify quiet=True
yum_cmd = 'yum info mariadb | grep Packages'
a = run(yum_cmd, quiet=True) #get response by '='
# To ignore non-zero return codes, specify warn_only=True
if run('mysql -uroot video', warn_only=True).find('Unknown database') != -1:
        cmd = "mysql -uroot -e '%s'" #Create the missing DB

2. Run a shell command on a remote host, with superuser privileges

fabric.operations.sudo(*args, **kwargs)

sudo("mkdir /var/www/new_docroot", user="www-data")
with settings(sudo_user='mysql'):
    sudo("whoami") # prints 'mysql'

3. Run a command on the local system

fabric.operations.local(command, capture=False, shell=None)


# Get output & don't print out
sql = local('cat script/mysql/init.sql', capture=True)


MainWiki: fab_api_operations (last edited 2015-04-22 00:06:09 by twotwo)