Last active
December 17, 2015 14:19
-
-
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".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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