Skip to content

Instantly share code, notes, and snippets.

@YellowSharkMT
Last active December 17, 2015 14:19
Show Gist options
  • Save YellowSharkMT/5623331 to your computer and use it in GitHub Desktop.
Save YellowSharkMT/5623331 to your computer and use it in GitHub Desktop.
Simple Fabric example script. Save it as "fabfile.py" in a folder, and open a shell up to that folder. Example commands: "fab prod test:AAAAAA", or "fab localhost tail".
# Most important thing to import
from fabric.api import *
# Not necessary, but useful for making timestamps
import time
# Allows Fabric to use profiles from your ~/.ssh/config file
env.use_ssh_config = True
def prod():
"Connects to production servers."
env.hosts = ['user@somehost'] # comma-separated list, like: ['host1','host2','host3']
def localhost():
"Connects to localhost."
env.hosts = ['user@localhost']
# optional decorator, runs commands in this function concurrently across all env.hosts
@parallel
def test(param1='a',param2='b'):
"Runs 'test' commands"
print('Params: %s %s' % (param1, param2))
run('ls -al')
def tail():
"Runs tail command..."
run('tail -f /var/log/apache2/other_vhosts_access.log')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment