FastHandle - IT Operations Examples

FastHandle is fast operation tools for infrastructure configurations and tests.

User Tools

Site Tools


Sidebar


Top     SiteMap

Manager Server

Target Server

$FHHOME/bin/xxx.sh | xxxx.exp













.

os:linux:check:index.html



This is an old revision of the document!


Top#OS Management

Check OS Status (check.py)

$FHHOME/fabfile/check.py


Operation

$ fab -l |grep check

$ fab -H $H auth.pro  check.xxxx

Remote Shell Commands

$ fab -H $H auth.pro -- systemctl get-default
$ FAB -H $H auth.pro -- systemctl set-default multi-user.target  # CUI


check.py

$FHHOME/fabfile/check.py

import sys, os
from fabric.api import *
from fabric.contrib import files

FHHOME=os.environ["FHHOME"]


#------------------------------------------------------------------
# check.ntpsync
#------------------------------------------------------------------
@task 
def ntpsync():
    sudo("which ntpq > /dev/null 2>&1 && ntpq -p")
    sudo("which chronyc > /dev/null 2>&1 && chronyc sources -v")


#------------------------------------------------------------------
# check.nmap
#     fab auth.pro check.nmap:22,x.x.x.x
#------------------------------------------------------------------
@task
def nmap(port, remote):
    """fab auth.pro ope.nmap:22,x.x.x.x"""
    run("nmap -Pn -sT -p %s %s " % (port, remote))



#===============================================================================
# Check OS Status
#===============================================================================
#------------------------------------------------------------------
# check.reboot_check
#------------------------------------------------------------------
@task
def reboot_check():
    date = datetime.now().strftime('%Y%m%d_%H%M')
    outfile = check_reboot.%s"  % (date)
 
    run("test -d scripts || mkdir scripts")
    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))

#------------------------------------------------------------------
# check.reboot_diff
#------------------------------------------------------------------
@task
def reboot_diff():
    run(ls -tr1 output/check_reboot.2* |tail -n 5)
    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")
    local("sdiff -s -w 150 %s %s" % (file1 file2))
    run("sdiff -s -w 150 output/%s output/%s" % (file1 file2)

#------------------------------------------------------------------
# check.ping_gw
#------------------------------------------------------------------
@task
def ping_gw():
    run("test -d scripts || mkdir scripts")
    put("%s/scripts/check_ping_gw.sh" % FHHOME, "scripts/check_ping_gw.sh, mode=0755)
    run("scripts/check_ping_gwt.sh")



#===============================================================================
#Service Enable/Disable
#===============================================================================
#-------------------------------------------------------------------------------
# CentOS7
#-------------------------------------------------------------------------------
@task
def check_systemctl_service():
    sudo("systemctl list-unit-files -t service --no-pager |egrep "enable|disable" |sort -k 3")
 


Scripts



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