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 auth.pro -- hostname


User and Group

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

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




Network

Interface

$ fab -H $H auth.pro -- "ip a |grep inet"


Bonding

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

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


Routing

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

$ fab -H $H auth.pro -- sudo /sbin/route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.0.1
$ fab -H $H auth.pro -- sudo route del -net 192.168.10.0 netmask 255.255.255.0
$ fab -H $H auth.pro -- sudo cp -p /etc/sysconfig/static-routes /etc/sysconfig/static-routes.`date -d '1day ago' +%Y%m%d`
$ fab -H $H auth.pro -- sudo "sed s/192.168.100.10/192.168.50.10/g /etc/hosts > /etc/hosts.`date -d +%Y%m%d`"
$ fab -H $H auth.pro -- "echo "any host 192.168.100.1 gw 192.168.0.5" >> /etc/sysconfig/static-routes"
$ fab -H $H auth.pro -- "echo 'any host 192.168.100.1 gw 192.168.0.5' >> /etc/sysconfig/static-routes"


Check Network Connection

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


tcpdump

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

  • -W1 -G30 is 30 seconds




DNS

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

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

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




Disk

$ fab -H $H auth.pro -- df -h
$ fab -H $H auth.pro -- mount




NTP

$ fab -H $H auth.pro -- chronyc sources
$ fab -H $H auth.pro -- chronyc sources -v
$ fab -H $H auth.pro -- ntpq -p




File

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

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


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

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


$ fab -H $H auth.pro -- tree -Dpuga  /etc/httpd




Kernel

Max open files

$ fab -H $H auth.pro -- cat /proc/`pidof nginx |awk '{print $1}'`/limits |egrep "Limit|open"
$ fab -H $H auth.pro -- 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 auth.pro -- "ps -ef |grep nginx"
$ fab -H $H auth.pro -- 'systemctl list-unit-files -t service --no-pager |egrep "enabled|disabled"'

RHEL/CentOS

$ fab -H $H auth.pro -- "sudo yum install -y openssl"

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

$ fab -H $H auth.pro --  "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 auth.pro -- sudo su - user1 -c \"ssh -i /home/user1/.ssh/id_rsa user1@server3 hostname\"






Top#How to use FastHandle



operation/one-line-task.html.txt · Last modified: 2018/03/19 23:52 by kurihara