Using Shell to develop a springboard machine

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.