Script to create temporary files:
#mktemp Create a temporary file or directory
#mktemp [OPTION] FILE. Randomlength
[OPTION]
-D Create a directory.
For example:
#mktemp/tmp/file. Xx
/tmp/file.36
#mktemp/tmp/file. Xx
/tmp/file.37
#mktemp/tmp/file. Xx
/tmp/file.38
#mktemp/tmp/file.xxxx
/tmp/file/1234
#mktemp/tmp/file.xxxx
/tmp/file/1235
#mktemp-D/tmp/file.xx
#ll
Drwxr-xr-x/tmp/file.33
Tips for use:
#FILE = ' mktemp/tmp/file.xx ' Saves the result to a FILE variable and can be called multiple times.
#echo $FILE
/tmp/file.33
#echo $FILE
/tmp/file.33
#unset FILE is not used when you delete a variable.
The script implements the signal capture:
9 and 15 cannot be captured.
CTRL + C = SIGINT terminated.
#trap capture the signal.
#trap ' COMMAND ' siglist
For example:
1. Achieve signal capture:
#vim a.sh
#!/bin/bash
Trap ' echo ' not end ' INT
While:;d o
Date
Sleep 2
Done
2. Write a script to test the host in the network segment, while cleaning up the temporary files generated by the script.
#vim ping.sh
#!/bin/bash
net=192.168.0
File=mktemp/tmp/file.xxx
Clearup () {
echo "Quit"
Rm-f $FILE
Exit 1
}
Tarp ' Clearup () ' Sigini
For I in {1..254};d o
If Ping-c 1-w 1 $NET. $I &>/dev/null;then
echo "$NET. $I is up" |tee >> $FILE
Else
echo "$NET. $I is Down"
Fi
Done
This article is from "Small Private blog" blog, please be sure to keep this source http://ggvylf.blog.51cto.com/784661/1615383
Bash scripts create temporary files and signal capture