The main purpose of the script is to practice capturing signals in a Linux bash script, by practicing the use of functions, and by terminating a running program, subsequent processing of files opened by the program, and so on!
Scripting Features:
Ping IP within a network segment, detect which IP is online, which IP is not online
command to Practice:
1, Mktemp
Usage: #mktemp/path/to/somefile.xxx where XXX can be multiple, is a string that is randomly generated by the system
-D Create as Directory
2, Ping test network is unobstructed
Usage: #ping [-C #] [-W N] IP
-C #, #表示指定ping的次数
-W n,n indicates a specified time-out
3. Trap Capture Signal
Usage: #trap ' COMMAND ' sign_table
Common signals are:
1:sighup function: To reread a process configuration file without restarting the process
2:sigint function: Interrupt a process, CTRL + C sends the signal
9:sigkill effect: To kill a process in any case, relative to signal number 15th
15:sigterm action: Will let it take care of its own affairs and then kill the process.
18:sigcont action: To keep a stopped process going
19:sigstop action: To make a process stop the job, CTRL + Z is sending the signal
4. Tee reads the standard input data and outputs its contents to a file
Usage: Tee [-A]/path/to/somefile
-A: Represents the attachment to the back of an existing file, rather than overwriting it.
Note: The tee instruction reads data from a standard input device and outputs its contents to a standard output device while saving to a file.
!/bin/bashnet=192.168.1file= ' Mktemp/tmp/file. XXXXXX ' Cleanup () {echo "quiting ..." rm-f $FILEexit 1}trap ' cleanup ' intfor I in {1..254};d o if ping-c 1-w 1 $NET. $I & ;>/dev/null; Then Echo-e "\033[32m$net. $I are up\033[03m" | tee-a $FILE Else ECHO-E "\033[31m$net. $I is down\033[03m" Fidon E
Interested friends, you can debug here, in the process of ping Press CTRL + C to try the effect Oh!
This article is from the "good if the water thick Tak" blog, please be sure to keep this source http://linux0s.blog.51cto.com/9529795/1873371
Ping a network segment of signal capture and function practice scripts in shell scripts under Linux