FastHandle - IT Operations Examples

FastHandle is fast operation tools for infrastructure configurations and tests.

User Tools

Site Tools


os:linux:ope:index.html



Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
os:linux:ope:index.html [2018/01/21 01:19]
kurihara
os:linux:ope:index.html [2019/02/11 00:41] (current)
kurihara
Line 1: Line 1:
 [[:index.html#OS Management|Top#OS Management]] [[:index.html#OS Management|Top#OS Management]]
-====== OS Operation (ope.py)=====+====== Linux Operation with Fabric (ope.py)=====
  
 $FHHOME/fabfile/ope.py $FHHOME/fabfile/ope.py
Line 10: Line 10:
  
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ echo xx.xx.xx.xx | fab auth.pro -- hostname 
-$ echo xx.xx.xx.xx | fab auth.pro -- sudo cat /etc/shadow 
- 
 $ fab  -l |grep ope. $ fab  -l |grep ope.
-$ echo xx.xx.xx.xx | fab  auth.pro  ope.check_user01+$ echo xx.xx.xx.xx | fab    ope.check_user01
 </sxh> </sxh>
  
 +\\
 +==== Fabric one-line Task Examples ====
 +<sxh bash toolbar:false gutter:false>
 +$ echo xx.xx.xx.xx | fab  -- hostname
 +$ echo xx.xx.xx.xx | fab  -- sudo cat /etc/shadow
 +</sxh>
  
 \\ \\
Line 24: Line 27:
  
 <sxh python toolbar:false gutter:false> <sxh python toolbar:false gutter:false>
-import sys+import sys, os
 from fabric.api import * from fabric.api import *
 from fabric.contrib import files from fabric.contrib import files
 from fabric.operations import open_shell from fabric.operations import open_shell
 +from datetime import datetime
  
 FHHOME=os.environ["FHHOME"] FHHOME=os.environ["FHHOME"]
Line 33: Line 37:
 #------------------------------------------------------------------ #------------------------------------------------------------------
 # ope.put # ope.put
-#     fab auth.pro ope.put:/home/fasthandle/rpm/abc.rpm,/tmp/abc.rpm+#     fab  ope.put:/home/fasthandle/rpm/abc.rpm,/tmp/abc.rpm
 #------------------------------------------------------------------ #------------------------------------------------------------------
 @task @task
 def put(local,remote): def put(local,remote):
-    """fab auth.pro ope.scp:/home/fasthandle/rpm/abc.rpm,/tmp/abc.rpm"""+    """fab  ope.put:/home/fasthandle/rpm/abc.rpm,/tmp/abc.rpm"""
     put("%s", "%s" % (local,remote))     put("%s", "%s" % (local,remote))
  
Line 43: Line 47:
 #------------------------------------------------------------------ #------------------------------------------------------------------
 # ope.ssh # ope.ssh
-#     fab auth.pro ope.ssh:"sudo vi /etc/hosts"+#     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 @task
-def ssh(cmd): +def sshcmd(cmd): 
-    '''fab auth.pro ope.ssh:"sudo vi /etc/hosts" '''+    '''fab  ope.sshcmd:"sudo vi /etc/hosts" '''
     open_shell("%s" % cmd)     open_shell("%s" % cmd)
  
Line 53: Line 68:
 #------------------------------------------------------------------ #------------------------------------------------------------------
 # ope.sudo_vi # ope.sudo_vi
-#     fab -H x.x.x.x auth.pro ope.vi:/etc/hosts+#     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' # WARNING: open_shell didn't use 'echo x.x.x.x |fab ' and 'fhghost.sh'
Line 60: Line 75:
 @task @task
 def sudo_vi(file): def sudo_vi(file):
-    """fab auth.pro ope.vi:/etc/hosts""" +    """fab  ope.vi:/etc/hosts""" 
-    open_shell("sudo_vi %s && exit" % (file))+    open_shell("sudo vi %s && exit" % (file))
  
  
Line 67: Line 82:
 #------------------------------------------------------------------ #------------------------------------------------------------------
 # ope.cp_p_1dayago(file) # ope.cp_p_1dayago(file)
-#     fab auth.pro ope.cp_p_1dayago:/etc/hosts+#     fab  ope.cp_p_1dayago:/etc/hosts
 #------------------------------------------------------------------ #------------------------------------------------------------------
 @task @task
 def cp_p_1dayago(file): def cp_p_1dayago(file):
-    """fab auth.pro  cp_p_1dayago:/etc/host,/etc/hosts""" +    """fab   cp_p_1dayago:/etc/host,/etc/hosts""" 
-    sudo("cp -p %s %s.`date -d '1day ago' +%Y%m%d`"% (file, file))+    sudo("cp -p %s %s.`date -d '1day ago' +%Y%m%d`" % (file, file))
  
  


os/linux/ope/index.html.1516465183.txt.gz · Last modified: 2018/01/21 01:19 by kurihara