FastHandle - IT Operations Examples

FastHandle is fast operation tools for infrastructure configurations and tests.

User Tools

Site Tools


os:linux:get: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:get:index.html [2018/01/03 02:30]
kurihara
os:linux:get:index.html [2018/07/11 00:04]
kurihara [get.py]
Line 1: Line 1:
 [[:index.html#OS Management|Top#OS Management]] [[:index.html#OS Management|Top#OS Management]]
-====== Get OS Conf (get.py) ======+====== Get Linux Configuration with Fabirc (get.py) ======
  
 $FHHOME/fabfile/get.py $FHHOME/fabfile/get.py
Line 7: Line 7:
 \\ \\
  
-===== Operation =====+===== Operation with Fabric =====
  
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
Line 14: Line 14:
 $ fab -H $H auth.pro  get.xxxx $ fab -H $H auth.pro  get.xxxx
 </sxh> </sxh>
 +
 +
 +
  
 \\ \\
Line 24: Line 27:
 from fabric.api import * from fabric.api import *
 from fabric.contrib import files from fabric.contrib import files
 +from datetime import datetime
  
 FHHOME=os.environ["FHHOME"] FHHOME=os.environ["FHHOME"]
Line 32: Line 36:
 #------------------------------------------------------------------ #------------------------------------------------------------------
 @task @task
-def get.file_remote_local(remote,local):+def file_remote_local(remote,local):
     """get.file_remote_local:/etc/hosts,hosts"""     """get.file_remote_local:/etc/hosts,hosts"""
     date = datetime.now().strftime('%Y%m%d_%H%M')     date = datetime.now().strftime('%Y%m%d_%H%M')
     hostname = run("hostname")     hostname = run("hostname")
-    outfile = %s/tmp/%s.%s.%s"  % (FHHOME local hostname date) +    outfile = "%s/tmp/%s.%s.%s"  % (FHHOMElocalhostnamedate
-    get("%s, %s" % (remote outfile))+     
 +    sudo("cp %s /tmp/%s" % (remote,date)
 +    get("/tmp/%s, %s" % (date, outfile))
     local("ls -lh %s" % (outfile))     local("ls -lh %s" % (outfile))
- +    run("rm -f /tmp/%s" % date) 
 #------------------------------------------------------------------ #------------------------------------------------------------------
 # get.sdiff_remote_local # get.sdiff_remote_local
-#     get.sdiff_local_remote:/etc/hosts,hosts+#     get.sdiff_remote_local:/etc/hosts,/home/fasthandle/conf/hosts.server1
 #------------------------------------------------------------------ #------------------------------------------------------------------
 @task @task
-def sdiff_local_remote(local,remote): +def sdiff_remote_local(remote,local): 
-    """get.sdiff_remote_local:/etc/hosts,/home/fasthandle/conf/hosts.server1"""+    """get.sdiff_remote_local:/etc/hosts,/home/fasthandle/conf/etc/hosts.server1"""
     date = datetime.now().strftime('%Y%m%d_%H%M')     date = datetime.now().strftime('%Y%m%d_%H%M')
     hostname = run("hostname")     hostname = run("hostname")
-    outfile = %s/tmp/%s.%s.%s"  % (FHHOME local hostname date) +    outfile = "%s/tmp/%s.%s"  % (FHHOMEhostnamedate
-    get("%s, %s" % (remote outfile)) +     
-    local("sdiff -s -w 150 %s %s" % (local outfile)) +    sudo("cp %s /tmp/%s" % (remote,date)
-    #local("/bin/rm -f %s" % (outfile))+    get("/tmp/%s, %s" % (date, outfile)) 
 +    local("sdiff -s -w 150 %s %s" % (outfile, local)) 
 +     
 +    run("rm -f /tmp/%s" % date) 
 +    local("rm -f %s" % outfile)
  
  
Line 63: Line 74:
     date = datetime.now().strftime('%Y%m%d_%H%M')     date = datetime.now().strftime('%Y%m%d_%H%M')
     yearmonth = datetime.now().strftime('%Y%m')     yearmonth = datetime.now().strftime('%Y%m')
-    outfile = systeminfo.%s.%s"  % (hostname date)+    outfile = "systeminfo.%s.%s"  % (hostnamedate)
    
-    local("test -d output/%s || mkdir output/%s"    % (yearmonth yearmonth))+    local("test -d %s/output/%s || mkdir %s/output/%s"  % (FHHOME, yearmonth, FHHOME, yearmonth))
     run("test -d scripts || mkdir scripts")     run("test -d scripts || mkdir scripts")
 +    run("test -d output || mkdir output")
    
-    put("%s/scripts/systeminfo.sh", "scripts/systeminfo.sh, mode=0755 % FHHOME+    put("%s/scripts/systeminfo.sh" % FHHOME, "scripts/systeminfo.sh", mode=0755) 
-    sudo("scripts/systeminfo.sh 1>output/%s  2>/dev/null"   % (outfile)) +    sudo("scripts/systeminfo.sh  1>output/%s  2>/dev/null"   % (outfile)) 
-    get("output/%s", "output/%s/%s"  % (outfile yearmonth outfile))+    get("output/%s", "%s/output/%s/%s"  % (outfile, FHHOME, yearmonthoutfile))
    
 </sxh> </sxh>
Line 78: Line 90:
  
 |<100% 200px ->| |<100% 200px ->|
-| [[os:get:scripts:systeminfo.sh.html]]       |+| [[os:linux:get:scripts:systeminfo.sh.html]]       |
  
  


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