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
Last revision Both sides next revision
os:linux:check:index.html [2018/01/03 02:36]
kurihara
os:linux:check:index.html [2018/03/14 00:31]
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 auth.pro 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>
  
 +
 +==== Example ====
 +
 +<sxh bash toolbar:false gutter:false>
 $ fab -H $H auth.pro  check.xxxx $ fab -H $H auth.pro  check.xxxx
 </sxh> </sxh>
 +
 +\\
 +==== Fabric one-line Task Examples ====
 +<sxh bash toolbar:false gutter:false>
 +$ fab -H $H auth.pro -- systemctl get-default
 +$ FAB -H $H auth.pro -- systemctl set-default multi-user.target  # CUI
 +</sxh>
 +
  
 \\ \\
Line 24: 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 43: Line 65:
 @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 56: 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", "scripts/check_reboot.sh, mode=0755 % FHHOME)+    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 68: 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 79: 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", "scripts/check_ping_gw.sh, mode=0755 % FHHOME)+    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 90: 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 |egrep "enable|disable" |sort -k 3")+    sudo('systemctl list-unit-files -t service --no-pager |egrep "enable|disable" |sort -k 3')
    
  
Line 102: 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.txt · Last modified: 2019/02/11 00:41 by kurihara