Execute remote program and display it locally
Copy Code code as follows:
Ssh-n-L Zouyunhao 192.168.2.14 "Ls-al/home/zouyunhao"
11.shell segment Annotation
Copy Code code as follows:
:
12. See if the network card is physically connected
Copy Code code as follows:
/sbin/mii-tool
13. See what the Linux system or MySQL error code means, such
The Linux shell is much more powerful in programming than in Windows batching, whether in loops or operations. There is no comparison of data types. The following is a summary of how an individual operates on an array while in use.
1. Array definition
[Chengmo@centos5 ~]$ a= (1 2 3 4 5)[Chengmo@centos5 ~]$ Echo $a
A pair of parentheses is an array, and the array elements are separated by a "space" symbol
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 inherits the environment variables of the current sh
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 is equivalent to a key, we here is equivalent
This article is part of the Linux Shell Series Tutorial (16), more Linux shell tutorials: Linux Shell Tutorials
The output and input redirection in the shell is a feature that is of
2.shell Tools2.1. log filesBrief introductionIt is important to create a log file, which records important information. In the event of an error, this information is very useful for our troubleshooting, and the monitoring information can be logged to the log file.Common methods of log filesLog files identified by timeExample#!/bin/bash# the current date current_date= ' date ' +%y%m%d ' #今天的日志文件名todaylog = ' log/${current_date}.log ' #如果日志文件不存在, create
The Shell function returns the value, generally has 3 kinds of ways: Return,argv,echo
1) Return statementThe return value of the Shell function, as in other languages, can be returned through the return statement.Example:
#!/bin/bash-
function mytest ()
{
echo "arg1 = $"
If [$ = 1]; then return
1
else
return 0
Fi
}
echo
echo "MyTest 1"
mytest 1
echo $? # Print return result
e
String-related operations are often involved in the shell batch process. There are a lot of command statements, such as: awk,sed can do various operations of string. In fact, the Shell has a series of operating symbols, you can achieve similar effects, you know, using the internal operator will omit the start of the external program and so on time, so the speed will be very fast.
First, judge read string v
Shell string comparisons, judging whether it's a number
Binary comparison operators, comparing variables or comparing numbers. Notice the difference between the number and the string.
Integer Comparisons
-eq equals, such as: if ["$a"-eq "$b"]
-ne is not equal to, such as: if ["$a"-ne "$b"]
-GT is greater than, such as: if ["$a"-gt "$b"]
-ge is greater than or equal to, such as: if ["$a"-ge "$b"]
-lt is less than, such as: if ["$a"-lt "$b"]
-le is
The content of this section:Keep the specified number of files remaining under the file system
Example:
Copy Code code as follows:
#!/bin/bash
#-------------------------------
#Description: Back Up your files
#site: Www.jb51.net
#-------------------------------
#shell variables
Path_source=/mnt/fifth/shell
Path_backup=/mnt/fifth/backup/shellbackup
path_delete=/mnt/fifth/tmp/rubbish/
Linux shell script Regular Expression instance explanation, shell instance explanation
I. concepts and features of Regular Expressions:
A regular expression is a logical formula for string operations. It uses predefined characters and combinations of these specific characters to form a "rule string ",
This "rule string" is used to express a filtering logic for s
comparing the timestamp implementation of the file /c2>-ef file, to determine whether File2 and File2 is the same file, by judging the two files pointing to the inode is the same to achieve, can be used in hard link decision# Two integers in a comparison-eq #equal equals -ne #not equal not equal -GT #greater than greater than - Lt # less than smaller than -ge #greater than or equal greater than or equal to-le # less than or equal smaller than or equal to# Multiple c
What is direct assignment?1. The way the author directly assigns parameter values is called direct assignment.2. In general, an indirect assignment is assigned by an interactive method.Example 1:varl=arppinging.comThis is a direct assignment that is directly assigned to a fixed value by the programming author.Example 2:[[emailprotected] ~]# read -p "Please enter a number:" var2Please enter a number:arppinging.com[[emailprotected] ~]# echo $var2arppinging.comThis is an indirect assignment.
For example, to compare strings, to determine whether a file exists and whether it is readable, and so on, usually use "[]" to represent the conditional test.Note: The space here is very important. To ensure that the square brackets are blank. I have been because of the lack of space or the wrong location, and waste a lot of precious time.If ...; Then....Elif ...; Then....Else....Fi[f "Somefile"]: To determine whether a file[-X "/bin/ls"]: Determine if/bin/ls exists and has executable permission
LS is the command to view files in directories and directoriesNow let's look at the use of this commandLsThe syntax of LS is mainlyLS View directory contentsLs-l Viewing folder detailsLs-a Viewing hidden filesLs-a view hidden files, but does not show "." and ".." Directory informationLs-d the directory as a file, rather than showing the file beneath itLs-h Display file size units (usually with other parameters)Ls-r recursively displays the contents of directories and subdirectoriesLs-s files fro
Need to use shell script every 3 seconds to monitor the running state of a software process, found that Crond seems to only support to the points, do not know seconds, how to do?
The first method:
Of course the first thought is to write a trigger script that uses a dead loop in the trigger script to solve the problem, as follows:
Cat kick.sh
Copy Code code as follows:
#!/bin/bash
While:;d o
/home/somedir/scripts.sh 2>/dev/null
Terminal printing
A terminal is an interactive tool through which users can interact with the shell environment. Printing text in a terminal is a basic task that most shell scripts and tools need to perform on a daily basis. Through the terminal printing, people can know the running state of the system, which is critical to the user.
echo Terminal printing
Copy Code code as follows:
echo
Copy Code code as follows:
#-------------------the wrong wording-------------------
RM-RF ${path}/*
#----------------------------------------------
#-------------------the right wording-------------------
If [-D "${path}"]
Then
RM-RF ${path}/*
Fi
#----------------------------------------------
7. Use of double brackets [[]]
The double middle bracket of the shell has many functions
Copy Code code as
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.