$FHHOME/fabfile/ope.py
$ fab -l |grep ope. $ echo xx.xx.xx.xx | fab ope.check_user01
$ echo xx.xx.xx.xx | fab -- hostname $ echo xx.xx.xx.xx | fab -- sudo cat /etc/shadow
$FHHOME/fabfile/ope.py
import sys, os from fabric.api import * from fabric.contrib import files from fabric.operations import open_shell from datetime import datetime FHHOME=os.environ["FHHOME"] #------------------------------------------------------------------ # ope.put # fab ope.put:/home/fasthandle/rpm/abc.rpm,/tmp/abc.rpm #------------------------------------------------------------------ @task def put(local,remote): """fab ope.put:/home/fasthandle/rpm/abc.rpm,/tmp/abc.rpm""" put("%s", "%s" % (local,remote)) #------------------------------------------------------------------ # ope.ssh # fab ope.ssh:"sudo vi /etc/hosts" # WARNING: This is too late for copy and past. So you use usually fhssh.sh #------------------------------------------------------------------ @task def ssh(): '''fab ope.ssh ''' open_shell("hostname") #------------------------------------------------------------------ # ope.sshcmd # fab ope.ssh:"sudo vi /etc/hosts" #------------------------------------------------------------------ @task def sshcmd(cmd): '''fab ope.sshcmd:"sudo vi /etc/hosts" ''' open_shell("%s" % cmd) #------------------------------------------------------------------ # ope.sudo_vi # fab -H x.x.x.x ope.vi:/etc/hosts # # WARNING: open_shell didn't use 'echo x.x.x.x |fab ' and 'fhghost.sh' # #------------------------------------------------------------------ @task def sudo_vi(file): """fab ope.vi:/etc/hosts""" open_shell("sudo vi %s && exit" % (file)) #------------------------------------------------------------------ # ope.cp_p_1dayago(file) # fab ope.cp_p_1dayago:/etc/hosts #------------------------------------------------------------------ @task def cp_p_1dayago(file): """fab cp_p_1dayago:/etc/host,/etc/hosts""" sudo("cp -p %s %s.`date -d '1day ago' +%Y%m%d`" % (file, file)) #------------------------------------------------------------------ # ope.reboot #------------------------------------------------------------------ @task def reboot(): sudo("shutdown -r now", warn_only=True) #------------------------------------------------------------------ # ope.shutdown #------------------------------------------------------------------ @task def shutdown(): run("shutdown -h now", warn_only=True)