Signal list:
Common commands related to Linux and signaling are the kill and trap commands, down how to use traps to control the springboard script using the command:
Command: Kill-l and Trap-l
Important signal and explanation of Linux system in enterprise actual combat
HUP (1) Hang
INT (2) Interrupt
Ouit (3) exit
ABRT (6) Abort
ALRM (14) Alarm
Term (15) termination
TSTP (20) stops the running of the process, but the signal may be processed or ignored
17.2 using trap control signals
The trap command user specifies that action is taken after the signal is received, a common use of trap is to complete the cleanup when the script is interrupted, or to block the user from illegally using certain signals and omit the SIC prefix when using the signal name.
#trap ' command, command ' signal number
Or
#trap ' command ' signal name
Test:
The signal name here is 2 (INT), and the result after Echo appears when using Crtl+c
At the command, if you use the ' ' to mask Ctrl + C function, ': ' Indicates an open function
Example 17: Processing multiple signals at the same time all of the shielding 0-60 of all digital signals, did not read here
Down time Trap Production application case
The trap command is placed in the script in the general sense. Execute the loop, and then press CTRL + C to execute the find Delete command
#!/bin/bash#author:huipenggang#mail:[email protected]trap "Find/tmp/xpg-type f-name" hui_* "| Xargs rm-f && Exit "2while truedo touch/tmp/xpg/hui_" ' Date +%f-%t ' "Sleep 4 ls-l/TMP/XPGDONE#LS/TMP/XPG
Execution Result:
Develop a springboard machine script:
The premise is to do the two on the top of the non-secret certification:
#!/bin/bashaa () {cat << EOF1. root 192.168.116.1352. Root 192.168.116.136*. Exiteof}fu () {for ((i=1;i<4;i++)) Echo-n "." Sleep 1done#echo-ne "\ n"------mashang------""}BB () {trap "" INT EXIT tstp aa echo "---------Mashang-----------" Fu Read-p "Your choices:" num case $num in 1) SSH 192.168.116.135;; 2) ssh 192.168.116.136;; 3) echo "This was bad" esac}bb
Using Shell to develop a springboard machine