FastHandle - IT Operations Examples

FastHandle is fast operation tools for infrastructure configurations and tests.

User Tools

Site Tools


os:linux:check: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:check:index.html [2018/01/10 13:30]
kurihara [check.py]
os:linux:check: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]]
-====== Check OS Status (check.py) ======+====== Check Linux Status with Fabric (check.py) ======
  
 $FHHOME/fabfile/check.py $FHHOME/fabfile/check.py
Line 7: Line 7:
 \\ \\
  
-===== Operation =====+===== Operation with Fabric ===== 
 +==== Print list of possible commands  ====
  
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -l |grep check+$ fab -l |grep -F check
 +    check.check_ssh_hostname                check_ssh_hostname:localuser,key,... 
 +    check.nmap                              fab  ope.nmap:22,x.x.x.x 
 +    check.ntpsync 
 +    check.ping_gw                           use  %s/scripts/check_ping_gw.sh 
 +    check.reboot_check                      use  %s/scripts/check_reboot.sh 
 +    check.reboot_diff 
 +    check.systemctl_service_enable_disable 
 +</sxh>
  
-$ fab -H $H auth.pro  check.xxxx+ 
 +==== Example ==== 
 + 
 +<sxh bash toolbar:false gutter:false> 
 +$ fab -H $H   check.xxxx
 </sxh> </sxh>
  
-==== Remote Shell Commands ====+\\ 
 +==== Fabric one-line Task Examples ====
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -H $H auth.pro -- systemctl get-default +$ fab -H $H  -- systemctl get-default 
-$ FAB -H $H auth.pro -- systemctl set-default multi-user.target  # CUI+$ FAB -H $H  -- systemctl set-default multi-user.target  # CUI
 </sxh> </sxh>
  
Line 31: Line 45:
 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 46: Line 61:
 #------------------------------------------------------------------ #------------------------------------------------------------------
 # check.nmap # check.nmap
-#     fab auth.pro check.nmap:22,x.x.x.x+#     fab  check.nmap:22,x.x.x.x
 #------------------------------------------------------------------ #------------------------------------------------------------------
 @task @task
 def nmap(port, remote): def nmap(port, remote):
-    """fab auth.pro ope.nmap:22,x.x.x.x"""+    """ope.nmap:22,x.x.x.x"""
     run("nmap -Pn -sT -p %s %s " % (port, remote))     run("nmap -Pn -sT -p %s %s " % (port, remote))
 +
 +#------------------------------------------------------------------
 +# check_ssh_hostname:localuser,key,remoteuser,remotehost
 +#------------------------------------------------------------------
 +@task
 +def check_ssh_hostname(localuser, key, remoteuser, remotehost):
 +    """ check_ssh_hostname:localuser,key,remoteuser,remotehost"""
 +    sudo ('su - %s -c "ssh -i %s %s@%s hostname"' % (localuser, key, remoteuser, remotehost))
  
  
Line 63: Line 86:
 @task @task
 def reboot_check(): def reboot_check():
 +    """ use  %s/scripts/check_reboot.sh """
     date = datetime.now().strftime('%Y%m%d_%H%M')     date = datetime.now().strftime('%Y%m%d_%H%M')
-    outfile = check_reboot.%s"  % (date)+    outfile = "check_reboot.%s"  % (date)
    
     run("test -d scripts || mkdir scripts")     run("test -d scripts || mkdir scripts")
-    put("%s/scripts/check_reboot.sh" % FHHOME, "scripts/check_reboot.sh, mode=0755)+    put("%s/scripts/check_reboot.sh" % FHHOME, scripts/check_reboot.sh, mode=0755)
     sudo("scripts/check_reboot.sh 1>output/%s  2>/dev/null"   % (outfile))     sudo("scripts/check_reboot.sh 1>output/%s  2>/dev/null"   % (outfile))
  
Line 75: Line 99:
 @task @task
 def reboot_diff(): def reboot_diff():
-    run(ls -tr1 output/check_reboot.2* |tail -n 5)+    run("ls -tr1 output/check_reboot.2* |tail -n 5")
     file1=run("ls -tr1 output/check_reboot.2* |tail -n 2 |head -n 1")     file1=run("ls -tr1 output/check_reboot.2* |tail -n 2 |head -n 1")
     file2=run("ls -tr1 output/check_reboot.2* |tail -n 1")     file2=run("ls -tr1 output/check_reboot.2* |tail -n 1")
-    local("sdiff -s -w 150 %s %s" % (file1 file2)) +    local("sdiff -s -w 150 %s %s" % (file1file2)) 
-    run("sdiff -s -w 150 output/%s output/%s" % (file1 file2)+    run("sdiff -s -w 150 output/%s output/%s" % (file1file2))
  
 #------------------------------------------------------------------ #------------------------------------------------------------------
Line 86: Line 110:
 @task @task
 def ping_gw(): def ping_gw():
 +    """ use  %s/scripts/check_ping_gw.sh """
     run("test -d scripts || mkdir scripts")     run("test -d scripts || mkdir scripts")
-    put("%s/scripts/check_ping_gw.sh" % FHHOME, "scripts/check_ping_gw.sh, mode=0755)+    put("%s/scripts/check_ping_gw.sh" % FHHOME, "scripts/check_ping_gw.sh", mode=0755)
     run("scripts/check_ping_gwt.sh")     run("scripts/check_ping_gwt.sh")
  
Line 97: Line 122:
 #------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
 # CentOS7 # CentOS7
 +# check.systemctl_service_enable_disable
 #------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
 @task @task
-def check_systemctl_service(): +def systemctl_service_enable_disable(): 
-    sudo("systemctl list-unit-files -t service --no-pager |egrep "enable|disable" |sort -k 3")+    sudo('systemctl list-unit-files -t service --no-pager |egrep "enable|disable" |sort -k 3')
    
  
Line 109: Line 135:
  
 |<100% 200px ->| |<100% 200px ->|
-| [[os:check:scripts:check_reboot.sh.html]]     | +| [[os:linux:check:scripts:check_reboot.sh.html]]     | 
-| [[os:check:scripts:check_ping_gw.sh.html]]  |   |+| [[os:linux:check:scripts:check_ping_gw.sh.html]]  |   |
  
  


os/linux/check/index.html.1515558633.txt.gz · Last modified: 2018/01/10 13:30 by kurihara