$ 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
$ H=test-server-1,test-server-2 $ fab -H $H -- hostname
$ 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"
$ fab -H $H -- "ip a |grep inet"
$ fab -H $H -- egrep "*" /proc/net/bonding/bond* $ fab -H $H -- egrep -i "mode|currently|status|count" /proc/net/bonding/bond*
$ 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 '"
$ fab -H $H -- sudo nmap -Pn -sT -p 22 xx.xx.xx.xx
$ 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
$ 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
$ fab -H $H -- df -h $ fab -H $H -- mount
$ fab -H $H -- chronyc sources $ fab -H $H -- chronyc sources -v $ fab -H $H -- ntpq -p
$ 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
$ 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"
$ fab -P --linewise -H host1,host2,host3 -- tail -f /var/log/access_log
$ fab -H $H -- "ps -ef |grep nginx" $ fab -H $H -- 'systemctl list-unit-files -t service --no-pager |egrep "enabled|disabled"'
$ 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"
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