1. Write the shell script and calculate the 1-100; 2. writing shell The script requires a number to be entered and then calculated from 1 to enter the number and, if required, if the number entered is less than 1 3. writing shell Script, put /root/ all directories (only one level) are copied to /tmp/ directory; 4. writing
Talk about the function call, I believe that everyone will not be unfamiliar, but for the beginner shell of me, Shell function call Way is a bit let me not very accustomed to, I also go a lot of detours, because the transfer of parameters when a very "natural" error, but also let me eat a lot of suffering, So summarize the method of calling functions in the shell.I. Definition of functions in the shellTo fa
1 about test testing, see the man documentationThe judgment of an expression(EXPRESSION) #EXPRESSION is True! EXPRESSION #EXPRESSION is FalseExpression1-a EXPRESSION2 #both is true,-o means orWhether the string is empty, equal-N string #the length of string is nonzero,-n can removed-Z String #the length of string is zero (nonexists,or null)#when comes to string, we use =STRING1 = STRING2 #the Strings is equalSTRING1! = STRING2 #the strings is not equalComparison of Numbers#when comes to number,w
Objective
I'm sure you all know that bash down time is a very useful command that can be timed for execution of a script or program, which is usually handy when it comes to a rough comparison of program execution efficiency. But you will find that the time text output by The Times command cannot be simply redirected, such as redirecting to a text file and only on the screen, which is inconvenient for non-interactive timing.
For example:
$ time Find. -name "mysql.sh" >1.txt real
0m0.08
This article describes how to read and write a MySQL database in a shell. This paper mainly introduces how to connect the MySQL database in the shell, how to create the database in the shell, create the table, insert the CSV file, read the MySQL database, export the MySQL database as XML or HTML file, and analyze the core statement. The method described in this a
To create a random number method:
Copy Code code as follows:
1~~~~
/dev/urandom
In Linux, a device/dev/urandom is used to generate random sequence of numbers. Using this device we can generate random strings when needed.
For example, we're going to produce a 8-digit random combination of letters and numbers, so you can:
Copy Code code as follows:
[Linux@test/tmp]$ cat/dev/urandom | head-1 | md5sum | Head-c 8
6baf9282
2~~~~
In fact, Linux has al
Learn Shell to now, always thought that they will not commit a very two problems, the result of this book last time made a very 2, integrity not protect AH!!! I'm under the test file path except wildcard * and? What can be used outside the same thing, the result of the $home under the implementation of RM. All right, the egg hurts for the whole afternoon! Return the wood to any one of the configuration files. Warn posterity, do not use RM Test wildcar
its file contents and enter it into the file file.txt
# tr-d ' \ r '
turn off the ability to automatically print input characters Stty-echo
reply to the function of automatically printing input characters stty Echo
trace function set-x is to perform trace function open,set +x is turn off tracking function
Eg:cat > aa.shSet-xEcho SS EchoSet +xEcho SDF EchoCtrl +dChmod +x aa.sh./aa.sh Execution
Automated Test Course Catalog
Ubuntu dash shell and bash shell Dash as/bin/shIn Ubuntu 6.10, the default system shell,/bin/sh, was changed to dash (the Debian almqualified Shell ); previusly it had been bash (the GNU Bourne-Again Shell ). the same change will affect users of Ubuntu 6.06 LTS upgrading dir
Shell Builtin variables (shell built-in variables) $ BASHThe path to the Bash binary itselfbash $ echo $ BASH/bin/bash $ BASH_ENVAn environmental variable pointing to a Bash startup file to be read when a script is invoked $ BASH_SUBSHELLA variable indicating the subshell level. this is a new addition to Bash, version 3.See Example 21-1 for usage. $ BASHPIDProcess ID of the current $ BASH_VERSINFO [n] A 6-e
Shell Command Line Operation, shell Command Line1.1 shell prompt
[Me @ linuxbox ~] $
If the last character is "#", it indicates that the current terminal session has the superuser permission. Use the root user to log on or use a terminal that provides the superuser permission to obtain this permission.
The prompt is defined by the environment variable named PS1 (
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 program_log_new.sh
function init_log(){sqlplus -S test/passw0rd@orcl
#! /Bin/sh .~ /. Bash_
[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 script (for log analysis) to obtain the shell output and then send an email.
Similar to a mo
6.shell function6.1. Defining functionsBrief introduction:The shell allows a set of command sets or statements to form an available block that becomes a shell functionDefining the format of a functionMethod OneFunction name (){Command 1......}Method TwoFunction name (){Command 1......}Two ways to define a functionFunctions can be placed in the same file as a piec
TopicAutomated maintenance of the system with shell scripts is simple, convenient and portable.But shell scripts are read-write and are likely to leak sensitive information, such as usernames, passwords, paths, IP, and so on.Similarly, sensitive information is also disclosed when a shell script is run.How do I encrypt a script without affecting the script to run?
Directory:CD: Switch directoriesCD path: Switch to the file pathCD ~[username]: Switch to the user's home directory,CD-: Switch to the directory where you firstPwd:pring working directory: Displays the current directorymkdir: Creating a Directory-P: Create the parent directory first, that is, recursively create-V: Show details at creation time650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/4C/D7/wKiom1RGG4DiW8iyAAD6ocweh14989.jpg "title=" Mkdir.png "alt=" Wkiom1rgg4diw8iyaad6ocweh1498
Often in the shell script to block other processes, such as MSMTP mail queue script, this script mutex is not correct, the following is the three found in the file to achieve mutual exclusion of the correct approach.
1. The Flock of Util-linux
This command has two uses: Flock Lockfile command (FLOCK-S 200; COMMAND; 200>lockfileflock need to keep open the lock file, which is not convenient for the second use, and the-s method specifies that the file
Use shell script to monitor whether a process exists without a startup instance, first on the code dry:
#!/bin/sh
ps-fe|grep processstring |grep-v grep
if [$-ne 0]
then
echo "START process ..."
else
#####Processstring represents a process feature string that can be queried to a unique process's character string0 indicates the existence of$? -ne 0 does not exist, $? -eq 0 Exists
Timed execution:
Crontab-e0 04,12,21 * * */bin/bash/home/my
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.