Skip to content

Instantly share code, notes, and snippets.

@hagiyat
Last active December 28, 2015 20:38
Show Gist options
  • Save hagiyat/7558331 to your computer and use it in GitHub Desktop.
Save hagiyat/7558331 to your computer and use it in GitHub Desktop.
# coding: utf-8
# python 2.7.5 / fabric 1.7.0
from fabric.api import env, run
from fabric.decorators import roles, task
from fabric.decorators import parallel
env.use_ssh_config = True
env.colorize_errors = True
env.warn_only = True
# 接続したいサーバーの定義
env.roledefs.update({
"production-srv": ["prod-srv%02d" % idx for idx in range(1, 12)],
"staging-srv": ["staging-srv%s" % chr(idx) for idx in range(ord('a'), ord('e'))],
"test-srv": ["test-srv%02d" % idx for idx in range(1, 2)]
})
# ファイルのパスとgrepの検索ワード指定
# $ fab -R [role] tailf:"/path/to/logfile", "grep-word"
@task
@parallel
def tailf(path="/path/to/logfile", grep=""):
try:
cmd = "tail -F %s" % path
if (grep):
cmd += " | grep %s" % grep
run(cmd)
except (KeyboardInterrupt, SystemExit):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment