function in shell, array in shell, demand analysis of alarm system

Source: Internet
Author: User

20.16-20.17 functions in the shell
    • 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.
格式: function f_name() {                     command                     }函数必须要放在最前面
    • Script Instance 1
#!/bin/bashfunction inp(){    echo $1 $2 $3 $0 $#}inp 1 a 2
    • Script Instance 2
#!/bin/bashsum() {    s=$[$1+$2]    echo $s}sum 1 2
    • Script Instance 3
#!/bin/baship(){    ifconfig |grep -A1 "$1: "|awk ‘/inet/ {print $2}‘}read -p "Please input the eth name: " ethip $eth
20.18 Arrays in the shell
    • Define array a= (1 2 3 4 5); Echo ${a[@]}

    • echo ${#a [@]} Gets the number of elements in the array
    • echo ${a[2]} reads the third element, array starting from 0
    • echo ${a[*]} equals ${a[@]} displays the entire array

Array Assignment

    • a[1]=100; Echo ${a[@]}
    • a[5]=2; Echo ${a[@]} An element is added automatically if the subscript does not exist
      Deletion of arrays
    • Unset A; Unset A[1]

Array shards

    • A= (seq 1 5)
    • Echo ${a[@]:0:3} starts with the first element and intercepts 3
    • Echo ${a[@]:1:4} starts with the second element and intercepts 4
    • Echo ${a[@]:0-3:2} Starts from the bottom 3rd element and intercepts 2
      Array substitution
    • Echo ${a[@]/3/100}
    • A= (${a[@]/3/100})
20.19 Alarm system Requirements Analysis
    • 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.
    • Requirements: Our machine roles are varied, but the same monitoring system is deployed on all machines, and the entire program framework is consistent, regardless of the role of all machines, depending on the role of the different configuration files.

Program Architecture

Under the bin is the main program;
Conf is the configuration file;
Shares is the various monitoring scripts;
Mail engine under mail;
Log is the journal.

function in shell, array in shell, demand analysis of alarm system

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.