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
Last revision Both sides next revision
os:linux:ope:index.html [2017/12/31 23:22]
kurihara
os:linux:ope:index.html [2018/03/14 00:33]
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
  
-\\ 
 {{INLINETOC}} {{INLINETOC}}
 \\ \\
Line 9: 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  auth.pro  ope.check_user01
 </sxh> </sxh>
  
 +\\
 +==== Fabric one-line Task Examples ====
 +<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
 +</sxh>
  
 \\ \\
Line 23: 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 36: Line 41:
 @task @task
 def put(local,remote): def put(local,remote):
-    """fab auth.pro ope.scp:/home/fasthandle/rpm/abc.rpm,/tmp/abc.rpm"""+    """fab auth.pro ope.put:/home/fasthandle/rpm/abc.rpm,/tmp/abc.rpm"""
     put("%s", "%s" % (local,remote))     put("%s", "%s" % (local,remote))
  
 +
 +#------------------------------------------------------------------
 +# ope.ssh
 +#     fab auth.pro 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 auth.pro ope.ssh '''
 +    open_shell("hostname")
 +
 +
 +#------------------------------------------------------------------
 +# ope.sshcmd
 +#     fab auth.pro ope.ssh:"sudo vi /etc/hosts"
 +#------------------------------------------------------------------
 +@task
 +def sshcmd(cmd):
 +    '''fab auth.pro ope.sshcmd:"sudo vi /etc/hosts" '''
 +    open_shell("%s" % cmd)
  
  
Line 51: Line 76:
 def sudo_vi(file): def sudo_vi(file):
     """fab auth.pro ope.vi:/etc/hosts"""     """fab auth.pro ope.vi:/etc/hosts"""
-    open_shell("sudo_vi %s && exit" % (file))+    open_shell("sudo vi %s && exit" % (file))
  
  
Line 62: Line 87:
 def cp_p_1dayago(file): def cp_p_1dayago(file):
     """fab auth.pro  cp_p_1dayago:/etc/host,/etc/hosts"""     """fab auth.pro  cp_p_1dayago:/etc/host,/etc/hosts"""
-    sudo("/usr/bin/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))
  
  
Line 71: Line 96:
 @task  @task 
 def reboot(): def reboot():
-    sudo("shutdown -r now, warn_only=True)+    sudo("shutdown -r now", warn_only=True)
  
 #------------------------------------------------------------------ #------------------------------------------------------------------


os/linux/ope/index.html.txt · Last modified: 2019/02/11 00:41 by kurihara