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













.

operation:one-line-task.html



Top#How to use FastHandle

Fabric one-line task examples in Linux

What is a one-line taks

$ fab [options] -- [shell command]

where everything after the -- is turned into a temporary run call, and is not parsed for fab options. If you’ve defined a host list at the module level or on the command line, this usage will act like a one-line anonymous task.

http://docs.fabfile.org/en/1.14/usage/fab.html#arbitrary-remote-shell-commands


Fabric Command Examples

Basic

$ H=test-server-1,test-server-2
$ fab -H $H  -- hostname


User and Group

$ H=test-server-1,test-server-2
$ fab -H $H  -- id nginx
$ fab -H $H  -- "cat /etc/passwd |grep xxx"
$ fab -H $H  -- "sudo cat /etc/shadow |grep xxx"
$ fab -H $H  -- "cat /etc/group |grep xxx"

$ fab -H $H  -- "echo 'root:PASS' | chpasswd"




Network

Interface

$ fab -H $H  -- "ip a |grep inet"


Bonding

$ fab -H $H  -- egrep  "*"  /proc/net/bonding/bond*

$ fab -H $H  -- egrep -i "mode|currently|status|count"  /proc/net/bonding/bond*


Routing

$ fab -H $H  -- netstat -rn
$ fab -H $H  -- cat /etc/sysconfig/static-route

$ fab -H $H  -- sudo /sbin/route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.0.1
$ fab -H $H  -- sudo route del -net 192.168.10.0 netmask 255.255.255.0
$ fab -H $H  -- sudo cp -p /etc/sysconfig/static-routes /etc/sysconfig/static-routes.`date -d '1day ago' +%Y%m%d`

$ fab -H $H  -- sudo sed -i s/192.168.100.10/192.168.50.10/g /etc/hosts

$ fab -H $H  -- sudo "bash -c 'sed s/192.168.100.10/192.168.50.10/g /etc/hosts > /etc/hosts.`date -d +%Y%m%d`  '"
$ fab -H $H  -- sudo "bash -c 'echo "any host 192.168.100.1 gw 192.168.0.5" >> /etc/sysconfig/static-routes  '"


Check Network Connection

$ fab -H $H  -- sudo nmap -Pn -sT -p 22 xx.xx.xx.xx


tcpdump

$ fab -H $H  -- sudo tcpdump  udp port 53 -i any  -W1 -G30
$ fab -H $H  -- sudo tcpdump -n not arp and not port 123 and not port 22  -W1 -G30

  • -W1 -G30 is 30 seconds




DNS

$ fab -H $H  -- cat /etc/resolv.conf

$ fab -H $H  -- host google.com
$ fab -H $H  -- host test-server-01
$ fab -H $H  -- host x.x.x.x
$ fab -H $H  -- host -t any google.com 8.8.8.8
$ fab -H $H  -- host -t soa google.com 8.8.8.8

$ fab -H $H  -- dig @8.8.8.8 google.com any
$ fab -H $H  -- dig google.com mx




Disk

$ fab -H $H  -- df -h
$ fab -H $H  -- mount




NTP

$ fab -H $H  -- chronyc sources
$ fab -H $H  -- chronyc sources -v
$ fab -H $H  -- ntpq -p




File

$ H=test-server-1,test-server-2

$ fab -H $H  -- sudo cp -p /tmp/test.txt /tmp/test.txt.`date -d +%Y%m%d`
$ fab -H $H  -- sudo cp -p /tmp/test.txt /tmp/test.txt.`date -d '1day ago' +%Y%m%d`


$ fab -H $H  -- diff /tmp/test.txt /tmp/test.txt.`date -d +%Y%m%d`
$ fab -H $H  -- diff /tmp/test.txt /tmp/test.txt.`date -d '1day ago' +%Y%m%d`

$ fab -H $H  -- sdiff -s /tmp/test.txt /tmp/test.txt.`date -d +%Y%m%d`
$ fab -H $H  -- sdiff -s /tmp/test.txt /tmp/test.txt.`date -d '1day ago' +%Y%m%d`


$ fab -H $H  -- tree -Dpuga  /etc/httpd




Kernel

Max open files

$ fab -H $H  -- cat /proc/`pidof nginx |awk '{print $1}'`/limits |egrep "Limit|open"
$ fab -H $H  -- cat /proc/`pidof httpd |awk '{print $1}'`/limits |egrep "Limit|open"




Log

Tailing log files on multiple machines

$ fab -P --linewise -H host1,host2,host3 -- tail -f /var/log/access_log

Refelrence Fabric: Tailing log files on multiple machines · Mark Needham




Package

$ fab -H $H  -- "ps -ef |grep nginx"
$ fab -H $H  -- 'systemctl list-unit-files -t service --no-pager |egrep "enabled|disabled"'

RHEL/CentOS

$ fab -H $H  -- "sudo yum install -y openssl"

$ fab -H $H  -- "rpm -q nginx"
# Check the installed rpm order by date.
$ fab -H $H  --  "rpm -qa --last | head -30"

$ fab -H $H  --  "sudo systemctl reload httpd.service"




SSH

Check Key
 FH Manager                   FH Target Server
 fasthandle@server1  --ssh--> fasthandle@server2
                                sudo su - user1
                                user1@server2  -- ssh --> user1@server3

[fasthandle@server1 ~]$ fab -H server2  -- sudo su - user1 -c \"ssh -i /home/user1/.ssh/id_rsa user1@server3 hostname\"


operation





Top#How to use FastHandle



operation/one-line-task.html.txt · Last modified: 2020/01/23 02:18 by kurihara