A. Trap
1.trap is a shell built -in command used to specify how signals are handled in the script. For example, pressing CTRL + C causes the script to terminate execution, in fact the system sends a SIGINT signal to the script process, and the default processing of the SIGINT signal is to exit the program. If you want to do not quit the program in CTRL + C, then you have to use the trap command to specify how the SIGINT processing. The trap command not only handles the Linux signal, but also specifies how the script exits (exit), Debug (Debug), Error (ERR), return, and so on.
Signals in the system:
650) this.width=650; "src=" Https://s5.51cto.com/oss/201711/16/26d958f51c6e08f69103b3fc60655ffd.png "title=" Screenshot from 2017-11-16 22-24-19.png "alt=" 26d958f51c6e08f69103b3fc60655ffd.png "/>
2.trap set-up and cancel
650) this.width=650; "src=" Https://s1.51cto.com/oss/201711/16/c73c624a51cbaff9981a5a0f154ff672.png "style=" float: none; "Title=" screenshot from 2017-11-16 22-32-05.png "alt=" C73c624a51cbaff9981a5a0f154ff672.png "/>
650) this.width=650; "src=" Https://s1.51cto.com/oss/201711/16/58b1c343ce57358e35c3247d51db7c4c.png "style=" float: none; "Title=" screenshot from 2017-11-16 22-35-07.png "alt=" 58b1c343ce57358e35c3247d51db7c4c.png "/>
650) this.width=650; "src=" Https://s5.51cto.com/oss/201711/16/87cdafcbd9d29ed1b73a1853555b1691.png "title=" Screenshot from 2017-11-16 22-37-55.png "alt=" 87cdafcbd9d29ed1b73a1853555b1691.png "/>
The 3.trap Practice Script
(1) The script cannot be canceled during execution and ends close :
650) this.width=650; "src=" Https://s2.51cto.com/oss/201711/16/0a1df007d61c3e2efe5b562a67eb7827.png "style=" float: none; "Title=" screenshot from 2017-11-16 22-41-00.png "alt=" 0a1df007d61c3e2efe5b562a67eb7827.png "/>
650) this.width=650; "src=" Https://s2.51cto.com/oss/201711/16/4cc55c4be9a3a8c6700beeb7e79ef7e3.png "style=" float: none; "Title=" screenshot from 2017-11-16 22-41-05.png "alt=" 4cc55c4be9a3a8c6700beeb7e79ef7e3.png "/>
(2) End display Byebye, end not remove trap:
650) this.width=650; "src=" Https://s3.51cto.com/oss/201711/16/a3b7a299e9cc6d29c8a31a73b27a6fe7.png "title=" Screenshot from 2017-11-16 22-43-03.png "alt=" A3b7a299e9cc6d29c8a31a73b27a6fe7.png "/>
To remove a trap at the end:
650) this.width=650; "src=" Https://s5.51cto.com/oss/201711/16/f9074050f71a2de21d9e0c1d0d06193e.png "title=" Screenshot from 2017-11-16 22-44-12.png "alt=" F9074050f71a2de21d9e0c1d0d06193e.png "/>
(3) Execute a script to find the file beginning with Westos, and delete the found file after terminating the script , do this experiment script to keep creating files
Xargs
650) this.width=650; "src=" Https://s1.51cto.com/oss/201711/16/c102ad6b051c7593049e32beb732bc8c.png "title=" Screenshot from 2017-11-16 22-54-11.png "alt=" C102ad6b051c7593049e32beb732bc8c.png "/>
650) this.width=650; "src=" Https://s1.51cto.com/oss/201711/16/150df745a1642650a987607757d19cd7.png "title=" Screenshot from 2017-11-16 22-45-53.png "alt=" 150df745a1642650a987607757d19cd7.png "/>
650) this.width=650; "src=" Https://s4.51cto.com/oss/201711/16/c3e0b902ee3dd777b5b0416eae86f6ee.png "title=" Screenshot from 2017-11-16 22-48-08.png "alt=" C3e0b902ee3dd777b5b0416eae86f6ee.png "/>
Installation of the service springboard for 4.TARP applications
(1) Configure the environment:
Rhel 6.5
server1:172.25.29.1 Springboard machine, user for jump
server2:172.25.29.2 Remote Landing Machine
server3:172.25.29.3 Remote Landing Machine
(2) configuration
Server1, Server2, Server3 all create jump users, set the password to Westos
650) this.width=650; "src=" Https://s3.51cto.com/oss/201711/16/62ce73fc87b8dd5ef6740905b4fb8a95.png "style=" float: none; "Title=" screenshot from 2017-11-15 12-00-46.png "alt=" 62ce73fc87b8dd5ef6740905b4fb8a95.png "/>,
(3) Create a secret login between Server1, Server2 and Server3
650) this.width=650; "src=" Https://s3.51cto.com/oss/201711/16/2ff050042164096bb0eb0c13fff23819.png "style=" float: none; "Title=" screenshot from 2017-11-15 12-01-03.png "alt=" 2ff050042164096bb0eb0c13fff23819.png "/>
650) this.width=650; "src=" Https://s3.51cto.com/oss/201711/16/0fa98fbba3e2391cc2bca8b2c15f25d0.png "style=" float: none; "Title=" screenshot from 2017-11-15 12-01-47.png "alt=" 0fa98fbba3e2391cc2bca8b2c15f25d0.png "/>
650) this.width=650; "src=" Https://s3.51cto.com/oss/201711/16/bb78be3734ebbbea3a5febf3ea536744.png "style=" float: none; "Title=" screenshot from 2017-11-15 12-01-59.png "alt=" Bb78be3734ebbbea3a5febf3ea536744.png "/>
(4) Set the script, put in the startup script directory, the content is to execute/mnt/trap/5.sh script as long as it is not root login
650) this.width=650; "src=" Https://s1.51cto.com/oss/201711/16/fa16b89ff88a9d0b8882a572212139ee.png "style=" float: none; "Title=" screenshot from 2017-11-15 11-40-37.png "alt=" Fa16b89ff88a9d0b8882a572212139ee.png "/>
650) this.width=650; "src=" Https://s1.51cto.com/oss/201711/16/258e4bfd059bd1dcd7ad480a0580e422.png "style=" float: none; "Title=" screenshot from 2017-11-15 11-40-15.png "alt=" 258e4bfd059bd1dcd7ad480a0580e422.png "/>
(5) Configuring the jump.sh Master script under/mnt/trap
650) this.width=650; "src=" Https://s2.51cto.com/oss/201711/16/0ca7d3cdefae99c3d07553aed88a158f.png "style=" float: none; "Title=" screenshot from 2017-11-15 11-59-28.png "alt=" 0ca7d3cdefae99c3d07553aed88a158f.png "/>
650) this.width=650; "src=" Https://s1.51cto.com/oss/201711/16/21cd95e2f6ef7eabd560296b1d528813.png "style=" float: none; "Title=" screenshot from 2017-11-15 11-59-05.png "alt=" 21cd95e2f6ef7eabd560296b1d528813.png "/>
650) this.width=650; "src=" Https://s2.51cto.com/oss/201711/16/d23c9cc5ab0ea1992315434ddfec282b.png "style=" float: none; "Title=" screenshot from 2017-11-15 11-59-10.png "alt=" D23c9cc5ab0ea1992315434ddfec282b.png "/>
(6) test, switch to jump user on Server1, interface switch execution jump.sh main script immediately
Note: Enter the springboard machine, no other operation, only remote login, unless you enter the specified options and password to exit
650) this.width=650; "src=" Https://s2.51cto.com/oss/201711/16/81d9d15476ea3da0cc555c599303e502.png "style=" float: none; "Title=" screenshot from 2017-11-15 11-59-46.png "alt=" 81d9d15476ea3da0cc555c599303e502.png "/>
Input 1, remote login Server2
650) this.width=650; "src=" Https://s2.51cto.com/oss/201711/16/ff82293dc4ee065f0bb813e540a5ecbb.png "style=" float: none; "Title=" screenshot from 2017-11-15 11-59-51.png "alt=" Ff82293dc4ee065f0bb813e540a5ecbb.png "/>
Input 2, remote login Server3
650) this.width=650; "src=" Https://s2.51cto.com/oss/201711/16/882dd91e5bf8e50cd24ee218e19454fc.png "style=" float: none; "Title=" screenshot from 2017-11-15 12-00-08.png "alt=" 882dd91e5bf8e50cd24ee218e19454fc.png "/>
Enter admin and password Westos to exit
650) this.width=650; "src=" Https://s3.51cto.com/oss/201711/16/294f644f2e40565780fd7936b7a1f5ed.png "style=" float: none; "Title=" screenshot from 2017-11-15 12-00-23.png "alt=" 294f644f2e40565780fd7936b7a1f5ed.png "/>
Linux shell script trap signal processing