FastHandle - IT Operations Examples

FastHandle is fast operation tools for infrastructure configurations and tests.

User Tools

Site Tools


operation:one-line-task.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
operation:one-line-task.html [2018/01/07 01:17]
kurihara
operation:one-line-task.html [2020/01/23 02:14]
kurihara
Line 1: Line 1:
 [[:index.html#How to use FastHandle|Top#How to use FastHandle]] [[:index.html#How to use FastHandle|Top#How to use FastHandle]]
-====== Remote Shell Commands ======+====== Fabric one-line task examples in Linux ======
  
 \\ \\
Line 6: Line 6:
 \\ \\
  
-===== What is Remote Shell Commands =====+===== What is a one-line taks =====
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
 $ fab [options] -- [shell command] $ fab [options] -- [shell command]
Line 17: Line 17:
  
 \\ \\
-===== Command Example =====+===== Fabric Command Examples =====
 ==== Basic ==== ==== Basic ====
  
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
 $ H=test-server-1,test-server-2 $ H=test-server-1,test-server-2
-$ fab -H $H auth.pro -- hostname+$ fab -H $H  -- hostname
 </sxh> </sxh>
  
Line 30: Line 30:
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
 $ H=test-server-1,test-server-2 $ H=test-server-1,test-server-2
-$ fab -H $H auth.pro -- id nginx +$ fab -H $H  -- id nginx 
-$ fab -H $H auth.pro -- "cat /etc/passwd |grep xxx" +$ fab -H $H  -- "cat /etc/passwd |grep xxx" 
-$ fab -H $H auth.pro -- "sudo cat /etc/shadow |grep xxx" +$ fab -H $H  -- "sudo cat /etc/shadow |grep xxx" 
-$ fab -H $H auth.pro -- "cat /etc/group |grep xxx"+$ fab -H $H  -- "cat /etc/group |grep xxx"
 </sxh> </sxh>
  
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -H $H auth.pro -- "echo 'root:PASS' | chpasswd"+$ fab -H $H  -- "echo 'root:PASS' | chpasswd"
 </sxh> </sxh>
  
Line 45: Line 45:
 ==Interface== ==Interface==
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -H $H auth.pro -- "ip a |grep inet"+$ fab -H $H  -- "ip a |grep inet"
 </sxh> </sxh>
  
Line 51: Line 51:
 ==Bonding== ==Bonding==
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -H $H auth.pro -- egrep  "*"  /proc/net/bonding/bond*+$ fab -H $H  -- egrep  "*"  /proc/net/bonding/bond*
  
-$ fab -H $H auth.pro -- egrep -i "mode|currently|status|count"  /proc/net/bonding/bond*+$ fab -H $H  -- egrep -i "mode|currently|status|count"  /proc/net/bonding/bond*
 </sxh> </sxh>
  
Line 60: Line 60:
 == Routing== == Routing==
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -H $H auth.pro -- netstat -rn +$ fab -H $H  -- netstat -rn 
-$ fab -H $H auth.pro -- cat /etc/sysconfig/static-route+$ fab -H $H  -- cat /etc/sysconfig/static-route
 </sxh> </sxh>
  
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ 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  -- 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  -- 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  -- 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  -- sudo sed -i s/192.168.100.10/192.168.50.10/g /etc/hosts 
-$ fab -H $H auth.pro -- "echo 'any host 192.168.100.1 gw 192.168.0.5>> /etc/sysconfig/static-routes"+ 
 +$ 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  '"
 </sxh> </sxh>
  
Line 76: Line 78:
 ==Check Network Connection== ==Check Network Connection==
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -H $H auth.pro -- sudo nmap -Pn -sT -p 22 xx.xx.xx.xx+$ fab -H $H  -- sudo nmap -Pn -sT -p 22 xx.xx.xx.xx
 </sxh> </sxh>
  
Line 82: Line 84:
 ==tcpdump== ==tcpdump==
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -H $H auth.pro -- sudo tcpdump  udp port 53 -i any  -W1 -G60 +$ fab -H $H  -- 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 -G60+$ fab -H $H  -- sudo tcpdump -n not arp and not port 123 and not port 22  -W1 -G30
 </sxh> </sxh>
-  * ''%%-W1 -G60%%''   is 60 seconds+  * ''%%-W1 -G30%%''   is 30 seconds
  
  
Line 92: Line 94:
 ==== DNS ==== ==== DNS ====
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -H $H auth.pro -- cat /etc/resolv.conf+$ fab -H $H  -- cat /etc/resolv.conf
  
-$ fab -H $H auth.pro -- host google.com +$ fab -H $H  -- host google.com 
-$ fab -H $H auth.pro -- host test-server-01 +$ fab -H $H  -- host test-server-01 
-$ fab -H $H auth.pro -- host x.x.x.x+$ 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
 </sxh> </sxh>
  
Line 104: Line 111:
 ==== Disk ==== ==== Disk ====
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -H $H auth.pro -- df -h +$ fab -H $H  -- df -h 
-$ fab -H $H auth.pro -- mount+$ fab -H $H  -- mount
 </sxh> </sxh>
  
Line 112: Line 119:
 ==== NTP ==== ==== NTP ====
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -H $H auth.pro -- chronyc sources +$ fab -H $H  -- chronyc sources 
-$ fab -H $H auth.pro -- chronyc sources -v +$ fab -H $H  -- chronyc sources -v 
-$ fab -H $H auth.pro -- ntpq -p+$ fab -H $H  -- ntpq -p
 </sxh> </sxh>
  
Line 123: Line 130:
 $ H=test-server-1,test-server-2 $ 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  -- 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  -- 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  -- 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  -- 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  -- 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  -- sdiff -s /tmp/test.txt /tmp/test.txt.`date -d '1day ago' +%Y%m%d`
  
  
-$ fab -H $H auth.pro -- tree -Dpuga  /etc/httpd+$ fab -H $H  -- tree -Dpuga  /etc/httpd
 </sxh> </sxh>
  
Line 142: Line 149:
 ==Max open files== ==Max open files==
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -H $H auth.pro -- cat /proc/`pidof nginx |awk '{print $1}'`/limits |egrep "Limit|open" +$ fab -H $H  -- 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"+$ fab -H $H  -- cat /proc/`pidof httpd |awk '{print $1}'`/limits |egrep "Limit|open"
 </sxh> </sxh>
 +
 +\\
 +\\
 +==== Log ====
 +=== Tailing log files on multiple machines ===
 +<sxh bash toolbar:false gutter:false>
 +$ fab -P --linewise -H host1,host2,host3 -- tail -f /var/log/access_log
 +</sxh>
 +Refelrence [[http://markhneedham.com/blog/2013/01/15/fabric-tailing-log-files-on-multiple-machines/|Fabric: Tailing log files on multiple machines · Mark Needham]]
 +
  
 \\ \\
Line 150: Line 167:
 ==== Package ==== ==== Package ====
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -H $H auth.pro -- "ps -ef |grep nginx"+$ fab -H $H  -- "ps -ef |grep nginx" 
 +$ fab -H $H  -- 'systemctl list-unit-files -t service --no-pager |egrep "enabled|disabled"'
 </sxh> </sxh>
  
 ==RHEL/CentOS== ==RHEL/CentOS==
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -H $H auth.pro -- "sudo yum install -y openssl"+$ fab -H $H  -- "sudo yum install -y openssl"
  
-$ fab -H $H auth.pro -- "rpm -q nginx"+$ fab -H $H  -- "rpm -q nginx"
 # Check the installed rpm order by date. # Check the installed rpm order by date.
-$ fab -H $H auth.pro --  "rpm -qa --last | head -30"+$ fab -H $H  --  "rpm -qa --last | head -30"
  
-$ fab -H $H auth.pro --  "sudo systemctl reload httpd.service"+$ fab -H $H  --  "sudo systemctl reload httpd.service"
 </sxh> </sxh>
 +
 +
 +\\
 +\\
 +==== SSH ====
 +== Check Key ==
 +<code>
 + FH Manager                   FH Target Server
 + fasthandle@server1  --ssh--> fasthandle@server2
 +                                sudo su - user1
 +                                user1@server2  -- ssh --> user1@server3
 +</code>
 +
 +<sxh bash toolbar:false gutter:false>
 +[fasthandle@server1 ~]$ fab -H server2  -- sudo su - user1 -c \"ssh -i /home/user1/.ssh/id_rsa user1@server3 hostname\"
 +</sxh>
 +
 +
 +
  
  


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