Shell Programming Application: Automated website backup and shell AutomationRsync is a data image backup tool in unix-like systems-remote sync. A Fast Incremental Backup Tool, Remote Sync, supports local replication or synchronization with other SSH and rsync hosts. Compared with traditional cp, scp, and tar backup methods, rsync has the advantages of high securi
Shell The technique of text slicing inIn the shell there is also a string slice this thing exists, has been used in Python slices, the following record the use of slices in the shell.(1) , replacing some of the text in the variable contents$var = "This was a line of text"$ echo${var/line/replaced}This is areplaced of text " Line be replaced by replaced . (2) ,
operating system (many commands support it, and more than 2000 commands are shell-supported)05. Default shell for common operating systemsLinux is Bourne Again shell (bash)Unix:solaris, FreeBSD default is the Bourne shell (SH), AIX is Korn shell (Ksh), HP-UX is the POSIX
variables
(1) $? 0 for success, not 0 for failure
[
[email protected]~]# Date
May 01, 2018 Tuesday 18:58:42 CST
[
[email protected]~]# echo $?
0
[
[email protected]~]# RM/
RM: Cannot delete "/": is a directory
[
[email protected]~]# echo $?
1
In the enterprise scenario, the use of the $? Return value is as follows:
① to determine whether a program, such as a command, script, or function is successfully executed
② call Exit N in the script, will return this number to $?.
③ in the function, the n
Sub-Library BackupEnterprise Actual Combat Problem 7: How to implement the MySQL database for sub-library backup, please use the script to implement#!/bin/Bashmysqluser=Rootpassword=Rootport=3306Socket="/usr/include/mysql/mysql.sock"Mysqlcmd="mysql-u$mysqluser-p$password-s $Socket"Database= ' $MYSQLCMD-E"show databases;"|egrep-v"Database|_schema|mysql"' MysqlDump="mysqldump-u$mysqluser-p$password-s $Socket"IP= ' Ifconfig enp0s3|grep"Broadcast"|awk'{print $NF}'`//CentOS 7backupdir=/backup/$IP [-D
Case statements are used to implement multiple if. else, but the usage is somewhat different, people who have learned other languages know that the case to match the variables, if there is a matching successful words to execute the corresponding statement. The case statement in Shell programming is also this meaning, cases will match the string, starting from the first mode, if a pattern has been matched su
This blog is simple to look at the loop statements that Shell programming uses, including for loops, while loops, until loops, for behind and a variable, and then a collection that assigns things to this variable, each loop, like a foreach in Java. While loops and if use the same condition to judge, satisfies the condition execution statement, until and while opposite, does not satisfy the condition executi
1. Limitations of single-quote strings:
Any character in a single quotation mark is output as is, and the variable in the single-quote string is not valid;
Single quotation marks cannot appear in single quote strings (not after using escape characters for single quotes).
2. Advantages of double quotes:
You can have variables in double quotes.
Escape characters can appear in double quotes
3. Stitching strings:4. Get the string length:5. Extract substrings:6. Look up substrin
1. Understanding Bash
Through the shell will input the instructions and kernel communication, let kernel control hardware workView Shell:cat/etc/shellA preset shell type is recorded in the/etc/passwd after login and is related to the accountCommand alias: Alias lm= ' Ls-al ' #注意有无空格Help: Man bashCommand types: Type
Copy Code code as follows:
Type ls # ls is aliased to ' Ls–color=auto '
Typ
Linux Shell script programming learning notes and practice, Script Programming learning notes
Http://www.1987.name/141.html
Shell Basics
Terminal printing, arithmetic operations, common variables
Search for specific strings in a specified directory in Linux and highlight matching keywords
Obtain the standard input
Standard input/output (read echo) of shell programming learning notes and shell learning notes
09:32:07
Input read:
Purpose:
Read a row from the standard input, or read a row from the file descriptor FD (file descriptor) and divide it into fields.
Usage:Read [-ers] [-a array] [-d separator] [-I buffer text] [-n read characters] [-N read characters] [-p prompt]
Common commands and statements for Shell programming (SCRIPT) and Common commands for shellSome common Shell programming (SCRIPT) commands and statements can meet general requirements.Command Parameters received:
Number of parameters:
$ #
Parameter value:
Command itself: $0 first parameter: $1 second parameter: $2
Linux (7) _ shell script programming, __shell Script Programming
I. What is a shell script?
In addition to a command interpreter, shell is also a programming language. A program written in she
Q: What is a shell and what is a shell script? The A:shell is a program written in C that is a bridge between the user and the Linux operating system. Users can either enter command execution and use shell scripting to accomplish more complex operations. It is a general designation of command Language, command interpreter program and
1.bash supports one-dimensional arrays (multidimensional arrays are not supported) and does not qualify the size of the array(1) define an array:Array_name= (value0 value1 value2 value3)OrArray_name= (Value0Value1value2Value3)or individually defined:Array_name[0]=value0Array_name[1]=value1Array_name[n]=valuen(2) Read array: ${array name [subscript]}Use the @ symbol to get all the elements in the array: Echo ${array_name[@]}(3) Get the length of the array#取得数组元素的个数length=${#array_name [@]}#或者Leng
to redirect stdout and stderr to file after merging, you can write:2>12>1(3) If you want both stdin and stdout to be redirected, you can write:Command A special redirect in 6.Here Document:shell to redirect input to an interactive shell script or program#它的基本的形式如下:: delimiter documentdelimiter! Content (document) between the #它的作用是将两个 delimiter is passed as input to command(1) At the end of the delimiter must be shelf write, the front cannot have
Shell Command Line writing rules
An understanding of the basic functions of shell command lines helps to write better Shell programs. When executing shell commands, multiple commands can be run on one command line, but the semicolon (;) must be used at this time (;) separate commands, for example:
[[Email protec
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.