20.16/20.17 function in Shell 20.18 array 20.19 Alarm system requirements in the shell

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. Format: function F_name () {?????????????? command????????} The function has to be on the front
Example 1
#!/bin/bash
Input () {
? ? echo $ $#
}

Input 1 A B

Example 2
#!/bin/bash
Sum () {
? ? S=$[$1+$2]
? ? Echo $s
}
Sum 1 2

Example 3
#!/bin/bash
IP () {
Ifconfig |grep-a1 "$:" |awk '/inet/{print $} '
}
Read-p "Please input ip_name:" ETH
IP $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
Uset 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.

20.16/20.17 function in Shell 20.18 array 20.19 Alarm system requirements in the shell

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.