The introduction to shell scripting is what this article is about, and we can use any type of text editor, such as Gedit, Kedit, Emacs, VI, to write the shell script, which must begin with the following line (must be placed on the first line of the
For the user to enter the validity of the date test is a very important issue, this example is simple to get the user entered the date, and converted to the appropriate format, but not perfect, why please read the text.
#!/bin/sh #
Monitor hardware Health
Shell monitor Cpu,memory,load average, log to log, when load pressure, email notify admin.Principle:1. Get the value of the Cpu,memory,load average2. Determine whether the value exceeds the scope of the customization, for
1. Examples of error methods
A
Var=1+1
Echo $var
The result of the output is 1+1, tragedy, hehe
b
Var=1
var= $var +1
Echo $var
The output result is 1+1, still tragic, hehe
2. The correct method
1) using Let
Var=1
Let "Var+=1"
Echo $var
The output
Get the number of rows in a single file
File: test1.sh
Number of rows: 20
Method One
Copy Code code as follows:
awk ' {print NR} ' test1.sh|tail-n1
As shown in the figure:
Method Two
Copy Code code as follows:
The shell script reads data in several ways:1. keyboard input, default2. read from the file3. Pass through Pipeline command
Functions of Echo:\c: No Line change\f: Paper Feed\ t: the jump Grid\ n: Wrapping Line\ represents escape, for example:
1, File type introductionLinux systems mainly include the following seven types of files: D directory-normal file L Symbolic link s socket file B block device file c character device file p named pipe file
2, Regular expressionRegular expressions
This paper introduces several common Linux monitoring scripts, which can realize the automatic monitoring and alarming of host network card traffic, system condition, host disk space, CPU and memory usage. According to their own needs to write a
In the Linux system for day-to-day operations or scripting, variables are more familiar with, but what are the types of variables, what is the difference in the specific usage? This paper is to share with you:
One, bash variable type:
Local
Arithmetic operations are essential in any programming language, and the shell is no exception.
First, use Let, (()) and [] for arithmetic operations
You can use the normal variable assignment method to define a numeric value, which is that it
First, Introduction
Environment variables are typically used to store path lists that are used to search for executables, library files, and so on. For example: $PATH, $LD _library_path, they usually look like this:
Copy Code code as follows:
This script has been tested on the Ubuntu and CentOS versions, and the script is as follows:
Copy Code code as follows:
#!/bin/bash
Line= ' =========== '
#linux发行版名称if [[-f/usr/bin/lsb_release]]; Thenos=$ (/usr/bin/lsb_release-a
First, the common skills
Copy Code code as follows:
SSH User@server Bash #ssh到远程服务器执行一个脚本, this command avoids uploading scripts to a remote server
SSH User@host Cat/path/to/remotefile | Diff/path/to/localfile-
One, logical operators
Logical Volume Label
Express meaning
1.
About the files and directories of the detection of logical labels!
-F
Common! Detect the existence of "archives" eg:if [-f filename]
INI file format is generally composed of sections, keys, values of three parts
Format:
[Section I.]First key = valueSecond key = second value[Section II]First key = Val1,val2,val3Example:
Copy Code code as follows:
[COM]
Kinggoo =
It's fun for the terminal print in the shell!First know that the end of the shell print has echo printf is commonly used is echo slightly;
Note: Font Color reset = 0, black = 30, red = 31, green = 32, ***=33, blue = 34, magenta =35, cyan = 36,
Example 1,Cut nginx logs by date and automatically delete logs generated seven days ago (logs have been synchronized to dedicated log storage servers, so you can safely delete historical logs .)#! /Bin/bash# InitializationLOGS_PATH =/data/nginx/logs/
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