Alibabacloud.com offers a wide variety of articles about linux shell scripting cookbook, easily find your linux shell scripting cookbook information here online.
-be-sustained by perpetual neglect of many and other things. Robert Louis Stevenson (1850-1894)
[Email protected]:~/shell/26zhang$
Note this:#grep "$ (date +%b '%-d, '%Y)"-A2 |Since my Ubuntu is in Chinese, I have not been searching for November. I'm going to replace it with this one, only 28, 2017.grep ", $ (date +%y)"-a2 | # Xcy AddIt would have been like this grep "$ (date +%-d, '%Y)"-A2 | # xcy Add, don't know why my date is 29. And the site is
/etc/crontab Add the following code: Here's an example of an hourly 26-minute execution: * * * * * root/home/**/wewang/autobackupmysql_qas.sh If executed at three O ' Day, then: XX 3 * * * root/home/**/wewang/autobackupmysql_qas.sh Case 2:redhat situation. ( that is, the currently used Linux system ) Copy the script you just edited to the appropriate directory
[Email protected]***** wewang]# CP autobackupmysql_qas.sh/etc/cron.da
file is a script that is executed when the Linux system startsEdit the Inittab file (use the Vim/etc/inittab command to open the file)Example: Add a statement to the Inittab file to allow the system to execute a shell script file that checks the system disk when it starts checkdisk.shcheckdisk::once:/sbin/checkdisk.sh >/dev/console 2>1 indicates that this command is executed at each runlevel, if it is to b
, which is represented as a local variable. such as local temp=1 .Example 3. Array Parameterstest3.sh#!/bin/bash Span class= "hljs-comment" ># trying to pass a array variable function testit {local newarray # use ' local ' define a local variable newarray= (' echo " the NewArray value is ${newarray[*]} "}myarray= (1 , 2 , 3 , 4 , 5 ) echo "the original array is:${ Myarray[*]} " testit $myarray Test:sh test3.shOutput:The original array is:1,2,3,4,5The NewArray value is 1,2,3,4,5Example
fileYou can also connect many parameters.such as Sort-t ': '-K 3 testYou can think of it as something inside. xxx1:xxx2:xxx3:xxx4:xxx5means to sort the xxx3-T: Specifies a character to distinguish the key position-K:--key=pos1[pos1]. The sort starts with pos1, and if POS2 is specified, it ends at Pos2.| Redirects the output of the du command to the sort command.-r: Indicates descending order.Here is an example:4.3.21. grep [options] pattern [file]For example:grep t test//Search for text in test
instruction (displays the exit status of the last command. 0 means no error, any other value indicates an error)$-shows the current options used by the shell, same as the SET command function[email protected] is similar to $*, but can be used as an array--------------------------------------------------------------------------------------------------#!/bin/sh##############Export lang= "ZH_CN. GB18030 "Export JAVA_HOME=/USR/LOCAL/JDKExport path= $JAVA
Previous Edit CommandA: Append data after the current cursorO: The next line of the cursor inserts dataDW Delete a Wordd$ Delete to end of lineDD: Delete Row, 5dd delete 5 rowsThe use of backspace and delete keys in normal mode is not recognized.10.1.4 Copy and pasteDD can be pasted with p after deletion.The copy command is Y,YW copy a wordy$ Copy to end of lineThen use p to paste10.1.5 Find Replacement: s/old/new/g a line command to replace all old, which is replaced only on one line: N,ms/old
sundo Echo ' Today is $var 1 ' donefor var2 in {1..10..2}doecho ' this is $var 2 "Donefor Var3 in $ (SEQ 1 2) Doecho" I had a/an $var 3 "Donefor VAR4 in $ (LS) Doecho" Here's the file $var 4 "doneWhile loop#!/bin/bashi=1while ((I SELECT statementThis SELECT statement to the time the wood has seen, run when you can interact with the user, run the following program to understand. If you don't break it, you're going to die.#!/bin/bashecho "which color do you like?" Select Var1 in red Green Bluedoe
handle non-file-name strings.#example.py##Example of using Shell-wildcard style matching in list comprehensions fromFnmatchImportFnmatchcase as Matchaddresses= [ '5412 N CLARK ST', '1060 W ADDISON ST', '1039 W GRANVILLE AVE', '2122 N CLARK ST', '4802 N BROADWAY',]a= [addr forAddrinchAddressesifMatch (addr,'* ST')]Print(a) b= [addr forAddrinchAddressesifMatch (addr,'54[0-9][0-9] *clark*')]Print(b)>>> ================================ RES
files under/var/logPut all the commands in one file and build up the script, here is the simplest command to stack up the script, empty the log script.Cd /var/logCat /dev/null > messagesEcho “Logs cleaned up.”Expand: Three ways to empty logs and file contents[[emailprotected] ~]# echo >test.log [[emailprotected] ~]# >test.log [[emailprotected] ~]# cat /dev/null >test.logScenario: Preserve files and empty content.Two Shell language and category Introd
, and the shell interprets the execution.• Batch processing (Batch): The user writes a shell script in advance, with many commands that allow the shell to execute the commands one at a time without having to hit the command one by one.
Shell scripts and programming languages are similar, there are variables and proces
These eight suggestions derive from the experience and lessons learned from key writers who have been writing shell scripts for several years. In fact, began to write more than these several, and then pondered repeatedly, remove a few insignificant, finally left eight. It is no exaggeration to say that each is a carefully chosen one, although a few are commonplace.
1. Specify bash
The first line of the shell
-rwxr-xr-x 1 root wheel 1103984 6 Nov 16:52 /bin/zsh
Advanced programming languages
In theory, as long as a language provides an interpreter (not just a compiler), the language is capable of scripting, and common explanatory languages can be used for scripting, such as Perl, TCL, Python, PHP, and Ruby. Perl is the oldest scripting language, and Pyth
the industry as a shell script, but reader friends know that Shell and shell script are two different concepts. For the sake of simplicity, the "shell programming" that appears in this article refers to Shell scripting, not the d
When deploying a task, one of the necessary procedures is to send some files, such as installation packages, to a large number of servers. Although there is already a Brother Woo script available: A Python script written by the SSH and SCP features provided by the Paramiko module. But I'm still in the fear of Python (though I've worked hard in my spare time), so I've written this batch SCP scripting tool using a combination of
This article collects a bunch of shell scripting tricks, I said, I write a blog mainly to make some learning notes to facilitate their own review, so I will make such an article, there is nothing incomprehensible. About the origin of these techniques, eh, I also forget, may come from Theunixschool, Commandlinefu, cool and igigo.net, of course, there are some of my own experience, tube him, into my brain is
folders, and ended up with a single command line:
xcopy /e C:\Windows\assembly\GAC_MSIL G:\GAC_MSIL
Then look for the desired assembly in the copied directory. Ha, now we can look at the PS code, it will be a very enjoyable thing.In addition, I found an additional assembly "System.Management.Automation.dll" through the _sfx_manifest_ file and the Reflector Analysis assembly reference, and its EXE note is "Microsoft Command-Line Shell
The role of the shell: between the system kernel and the user, is responsible for interpreting the command line.
·
Shell programs that are used by default after logging in, typically/bin/bash
Different shell internal instructions, operating environment, etc. will differ
[Email protected] ~]# Cat/etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
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.