The command line can execute multiple commands at once, in the following ways:1. Separate each command;Note: The execution of each command will not affect the execution of other commands. In other words, each command executes,However, there is no
Determines whether the current user is the root administrator, and if so, executes the tar to perform a backup of the/etc/directory.#!/bin/bash# IF Current user was root then backup the/etcIf ["$ (id-u)"-eq 0];thenTar-czf/root/etc.tar.gz/etc
Shell scripting is the most basic knowledge of our OPS management, and here are a few examples of my learning process (compared to Daniel). The purpose of this blog is to record the course of learning scripts, but also to be able to discuss learning
Remote SCP file by using reverse CT in shell script: Before using reverse CT, you need to install two RPM packages: # rpm-ihv centos/expect-5.43.0-5.1.i386.rpm
# Rpm-ihv centos/expect-devel-5.43.0-5.1.i386.rpm or yum directly download and install
Common shell script interpreters in Unix/Linux include bash, sh, CSH, and KSh. Bash is the most common interpreter in Linux.
Script Language isInterpreted languageWhen executing such programs, the interpreter (Interpreter) needs to read the source
I. Condition statements
1,
If [expression]
Then
# Code block
Fi
2,
If [expression]
Then
# Code block
Else
# Code block
Fi
3,
If [expression]
Then
# Code block
Else if [expression] # Replace this field with Elif [expression]
Then
# Code block
Else
#
#! /Bin/bash
Hello = "var1"
Echo $ hello
Function func1 # define function func1
{
Local Hello = "var2" # define the internal variable hello
Echo $ hello
}
Func1 # Call a function
Echo $ hello
Execution result:
Conclusion: local variables only work
Echo-e "\ e [1; 31 m This is red text \ e [0 m"
\ E [1; 31 m set the color to red, \ e [0 m "will reset the color.
Each color has a corresponding color code, resetting 0, black 30, red 31, green 32, Blue 34, Magenta 35, cyan 36, white 37
To set
1. you can set the number of servers to be checked and the server to check. You can set the IP address of the non-Online host and the corresponding time of the non-Online host, and collect statistics on the number of non-Online hosts saved to the
It is easier to parse and modify XML using python, but if it is not convenient to use python, you can simply replace it with the SED command
For example, to replace the value of the port number in the following line:
21
You can use:
New_port =
Traditional if statements -- use conditional expressions as if conditionsIf [conditional expression]ThenCommandCommandCommandElseCommandCommandFiConditional expressionsFile expressionIf [-F file] If the file existsIf [-d...] If the directory
In shell programming, some string variables are often processed. For example, commands such as awk, expr, sed, and TR are often used to calculate length, intercept substring, and replace character. Next we will introduce a simple string processing
In Linux, shell variables $ #, [email protected], $0, $1, $2 are interpreted as follows:Variable description:$Shell PID (processid)$!PID of the background process last run by Shell$?End code of the last command (return value)$-Flag overview set by
Start:The URL of svnis in excel. I copied it to txt.pdf, while VIOs only extracted the URL and saved it as url.txt.You can use VI to process url.txt, add SVN checkout, and other words to become the svn. Sh that can be run. Each row isSVN checkout.../
File descriptorBefore a process reads a file, it needs to open the file. When the process opens the file, Linux associates the file with a number (called a file descriptor ), the file descriptor is an index of the opened file in the input table.
String truncation method in shell programming:
1. the GNU Linux Shell intercepts the first eight characters of the character variable by using the following methods:
1. expr substr "$ A" 1 8
2. Echo $ A | awk '{print substr (, 1, 8 )}'
3. Echo $ A |
Preface when using bash shell to write a program, the for loop is often used, especially the requirement from 1 to 100. Here we record the C language of several types of loop methods from 1 to 100 in shell.
[HTML]View plaincopyprint?
For (I = 1; I
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