first, the implementation1, parallel execution of commands, multiple commands separated by semicolons[Email protected] network-scripts]#Date;W.H.O.Tue May3 -: -: -Cst .Root Tty1 .- to-Geneva on: +Root pts/0 .- to-Geneva -: A(192.168.78.1)2. The first line of the shell script indicates that bash is required to execute#! /bin/bash3. Shell scripts are exe
Open a text editor, create a new file, the extension sh (sh for Shell), the extension does not affect the execution of the script, see the name is good, if you write a shell script in PHP, the extension is good with PHP.Enter some code:#!/bin/bashecho"Hello world! " ""#!" is a contract tag that tells the system what in
“#! Magic Number: The general specification at the beginning of the script, used to specify the interpreter to execute the contents of the script. Note: Only the first line of the script #! Valid, followed by a comment! If you do not specify an interpreter, the default shell execution
The operation of a numeric variable:
The numerical operation of the shell variable is mostly used in the process control of the script, in the shell environment, only a simple integer operation, does not support the fractional operation, the integer value operation mainly through the internal command expr execution. The following is the basic formatExpr
1. I wrote a PHP script to execute some shell scripts through the Web interface.
The 2.shell script will use sudo
3.sudo user has set the Nopassword
4. Manually in the nobody User environment, (su-s/bin/bash nobody), and then execute the shell
In general, you may need to switch the root user to another user for execution during the automation process, such as: OralceHowever, the execution of the command will return to the root user, continue to execute other commands under the root user.You need to know the parameters of the SU command-C or-sLike what:# su-oracle-c "PWD"/home/oracleOrSu-oracle-s/bin/sh test.shThe relevant commands in the test.sh executed at this point are to be bin/sh, in other words, bin/sh supported commands can be
Simple summary of Shell scripts and tips in script writing mainly summarize the entry-level bash from the following aspects: 1. Command History, command completion 2. pipelines, redirection 3. command alias and command replacement 4. command line editing 5. file name wildcard 6. Bash-related configuration files and variables 7. programming (entries... simple summary of
Environment:
SSH server:192.168.100.29 server.example.comSSH client:192.168.100.30 client.example.com
Create secret key authentication through root user to implement Shell script management, distribution, deployment
First, the client side creates the secret key pair and distributes the public key to the SSH server that needs to be logged on
Note: The public key is equivalent to a lock, the private key i
[Shell] crontab executes the task and calls the shell script. The relative path cannot be found. crontabshell
The scenario where the problem occurs is probably
1 cron calls a python script
2. In the python script, call a shell
The key to using command-line arguments is that the shell script needs to interact with the person who is running the script.The bash shell provides command-line arguments to add data values after the command, command line options to modify the command behavior of single character values, and direct read keyboard input.
1, command line parametersThe most basic w
1, in the assignment statement Name=value can not have a space, for example: name = value of the form is considered to be three variables, because essentially, the content of the script is passed to the shell program variables, and the variables are separated by a space. If you want a space in value, you need to quote it in quotation marks, and the content of the variable you want to apply is marked with a
Common shell script running Log Module, shell logTarget
Implement recording of SHELL execution start time, end time, running status, error information, etc. Use the function to encapsulate log records and use scripts to call functions.Source code universal function script pr
Preface:
Through studying spark cluster scripts, take notes on some important shell script skills.
*). Get the directory of the current script
sbin=`dirname "$0"` sbin=`cd "$sbin"; pwd`
Code comments:# The above code is a common technique for getting the directory where the execution script is located# Sbin = $ (dirnam
There are three ways to invoke external scripts when running shell scripts, exec (exec script.sh), source (source script.sh), fork (./script.sh)EXEC (exec/home/script.sh):Using Exec to invoke the script is equivalent to executing a command in the current shell, without generating a new process, and the executed script
Programs on the Linux server update the MySQL database every day, so remember to write a shell script, combined with crontab, to back up the database regularly. Actually very simple, the main is to use the mysqldump command with MySQL.
#!/bin/bash # Shell script to backup MYSQL database # to backup nysql databas
The shell also has a real debug mode. If there are errors in the script "Strangescript", you can debug this:
Sh-x Strangescript
This executes the script and displays the values of all the variables.
The shell also has a pattern that does not need to execute a script ju
One, single branch if statement
Format: if judge condition; then
Statement1
statement2 ...
Fi
Two, two-branched if statement
Format: if judgment condition; Then
Statement1
statement2 ...
else
statementn
...
Fi
Use a previously used script to illustrate this structure.
Three, multiple branch if statement
Format: If Judge condition 1;then
Statement1 ...
Elif judgment Condition 2; Then
statement2 ...
Elif judgmen
1. "" "" "The Difference," "The variables will be resolved" "All of them as strings" "to execute system commands
2. The custom variable defaults to a local variable, and the environment variable is a global variable.
3.export can set one or more variables as global variables
4. To use a variable in a child shell in the parent shell, you must set the variable to global with export
5. Commonly used enviro
SHC can be used to encrypt shell scripts, which can be converted into an executable binary file. After SHC the shell script, it generates two new files at the same time, one is the encrypted executable binary (the filename ends with. x), and the other is the original file in C (the filename ends with the. x.c).Here's how to install, SHC, and use examples:Download
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.