One, the function in shell script?
- The function is to organize a piece of code into a small unit, and give the small unit a name, when the code is used to call the name of the small unit directly.
Format: function F_name ()
{
command} function must be placed at the front
- Example 1 output the specified parameters
#!/bin/bashinput() { echo $1 $2 $# $0}input 1 a b
#!/bin/bashsum() { s=$[$1+$2] echo $s}sum 1 2
Ii. Arrays in the shell
Array shards
a=(`seq 1 5`)echo ${a[@]:0:3} 从第一个元素开始,截取3个echo ${a[@]:1:4} 从第二个元素开始,截取4个echo ${a[@]:0-3:2} 从倒数第3个元素开始,截取2个数组替换echo ${a[@]/3/100} //将数组a中的3替换成100(只显示到屏幕,并不更改数组)a=(${a[@]/3/100}) //将数组a中的3替换成100
Three, Shell project-alarm system
- Requirements: Use the shell to customize a variety of personalized alarm tools, but the need for unified management, standardized management.
- Idea: Specify a script package that contains the main program, subroutine, configuration file, mail engine, output log, and so on.
- Main program: As the entire script portal, is the lifeblood of the entire system.
- Configuration file: is a control center that uses it to switch individual subroutines, specifying each associated log file.
- Subroutine: This is the real monitoring script, used to monitor each indicator.
- Mail Engine: It is implemented by a Python program that defines the server to which the message is sent, the person who sent it, and the sender's password
- Output log: The entire monitoring system should have a log output.
Functions, arrays
in 71.shell