not need to back up the Data= ' tail-1 $filename ' if[ $data "== "$comparedata" ];then echo "' Date ' rmanbackupsucess" >>/ops/tarlog else echo "' Date ' Rmanbackup Fail "NBSP;AMP;GT;GT;NBSp;/ops/tarlog exit2 fi #tarbackupfileandmoveto Backupserver #将当天的备份集压缩备份出来并move至对应nfs提供的文件夹, my 300GB backup compressed as long as 30 g, compression ratio is still very amazing/usr/bin/find/mnt/rman- name ' oradb1* ' >/ops/tarlist foriin '/bin/cat/ops/tarlist ';d o echo ' Date ' tar $i start >>/ops/tarlog
= (1 2 3 4 5 6 7 8 9) #定义一个求和函数sum () { result=0 for var in [email protected] do
result=$[$result + $var] done Echo $result} #输出数组的长度echo "Length of output array: ${#numberArray [@]}" #输出数组中指定的值echo " The value specified in the output array: ${numberarray[2]} "#修改数组指定的值numberArray [2]=4echo" to modify the value after the array specified: ${numberarray[2]} "#调用函数, using the array variable echo" to invoke the function, Use array variable: ' Sum ${numberarray[*]} ' "
Operation
protected]
Same as $*, but quoted when used, and returns each parameter in quotation marks
$-
Displays the current options used by the shell, same as the SET command function
$?
Displays the exit status of the last command. 0 means no error, and any other value indicates an error
Shell Process ControlIf ElseFormat:
If condition
Then
C
True when the length of a string is greater than 0
-Z str1
True when the length of a string is 0
Str
True when the string is non-empty
As an example, compare strings to test the user id:If ["$ (whoami)"! = ' root ']; Thenecho "You had no permission to run $ as Non-root user."Exit 1;Fi
Numeric comparison (integer)
operator
Compare Results
Num1-eq num2
Two numbers equal to True
Linux shell scripting:1. Program Structure Exercise: Write a script, given a positive integer, to calculate the sum of all digits of this number.For example, if the program is given input 123, it should return 1+2+3=6.2. Program Structure Exercise: Write a script, given a positive integer, to output this number in reverse order.For example: program input 123, then should output 321.3.Linux Command +
How to protect a shell program you've writtenTo protect your own shell scripting program, there are many methods, the simplest way there are two: 1, encryption 2, set the expiration time, following the SHC tool as an example description:I. Download and install the SHC toolSHC is a tool for encrypting shell scripts. Its
"array is:" ${lengthn}#Shell Pass Parametersecho "Executed file name: $"echo "First parameter: $ $"echo "The second parameter is: $"#Shell operator: Native bash does not support simple math operations, but can be implemented with other commands, such as awk and expr,expr, which are most commonly used.#expr is an expression calculation tool that uses it to perform the evaluation of an expression.#算数运算符Val=
1.Shell command line writing rules:Multiple commands can be executed on a command line, but required;Long command statements can be expanded with \ on the command line2. Execute Shell Program2.1./test.sh2.2 Bash test.sh2.3 In order to compile and execute the shell-written program in any directory, add the/bin directory to the entire environment variableExport Pat
shell and returns the given valueIn general, exit 0 means that the program ends normallyIf exit is not a value of 0, the program produces an error.In the case of the shell, after calling your program in the shell, use echo $? command to see the exit value of your program. In a shell script, it is usually based on the
: #! /bin/shecho "Enter password:" Read trywhile ["$TRY"! = "secret"]; Do echo "Sorry, try again" Read Trydone The following example controls the number of cycles by arithmetic operations: #!/bin/shcounter=1while ["$COUNTER"-lt]; do echo "Here's Go Again" counter=$ (($COUNTER + 1)) done(3) Case and while combination#!/bin/bashwhile: : True, always loop do the command to loop execution echo-n "Enter any number [1-
There are some files and folders under the current folder, and there are several. txt files in each folder.Now requires a new folder to be created in the current folder all, and those folders all. txt filesare copied to the folder all. The shell script implementations in ubuntu12.04 such as the following:#!/bin/sh# Hint Informationecho "Start:"# define VariablesDst=allPst=.txt# Copy files to target directoryIf [-D ${DST}]Thenecho "${DST} existed"Elsee
Shell common system Variable resolution: $ $ The name of the current script $n the nth parameter of the current script, n=1,2,...9$* all parameters of the current script (excluding the program itself) $# the number of arguments to the current script (excluding the program itself) $? When a command or program finishes executing, a general return of 0 indicates a successful execution. $UID Current user's id$pwd current directory $$ is the current proces
directory exists-D: Determine if the directory is not present and whether it exists-F: Determine if the file is normal and exists-R: Determine if the document has Read permissions-W: Determine if Write permission is available-X: Determine if executableIf you use the If judgment, the format is: if [-e filename]; Then5, echo xxx >> filename is to append the content to the file to the lastecho XXX > FileName Clears the contents of the file and then writes the new content6. No spaces between equals
1, #!/bin/shThe first line tells the operating system that the interpreter for this script is/bin/sh this executable file2. While loop:#!/bin/shSleep 1; echo "User"; \Sleep 1; echo "Password"; \While true; Do \echo "Output"Sleep 1; \Done3, the shell script realizes the automatic input of Telnet, implements with the pipeline, the last while loop is used to give the last command full execution time(Sleep 1; echo "user"; \Sleep 1; echo "Password"; \Sleep
:
Traverse:
For ip_t in ${servers[*]};d o If ["$" = "$ip _t"];then is_ip_correct=true break FidoneCall other programs:
Use ', and get the output result:
ps3= "Please choose a branch:" Select Branch in' svn list svn://;d o if [$branch];then svn_dir= "svn://
using $ (), and obtain the output result:
today=$ (Date+%y-%m-%d/%h:%m:%s)svn_version=$(SVN info $SVN _dir | grep "Last Changed Rev:" | awk ' {print $4} ')
Invoke other programs silently (with
1. After opening the terminal prompt, $ represents a normal user, #表示管理员用户root, root is the most privileged user in the Linux system.2. A shell script is usually a text file with a #! start, where #! precedes the interpreter path. Example: #!/bin/bash3. Note section starts with #, and consistently continues to the end of the line4. By default, Echo adds a line break after each call. The text after echo can be enclosed in double quotation marks, with s
htxk-106 host information phenomenon is as follows:by Zabbix_get commandZabbix_get [7189]: Check access Restrictions in Zabbix agent configurationWorkaround: By viewing Zabbix related files, found in the Usr/local/sbin directory Zabbix_agend file, the time to view the file is July, should be on the secondary machine previously installed Zabbix caused,After you delete the file, restart it:To the point where the problem has been solved, the same problem can occur when the 192.168.10.113 machine is
The remaining space is Morethan the%, the message is sent to the Wl#tue2 the: $: AboutCst .PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/wl/Binexport PATH forRemainingspaceinch$(DF-H |awk '{print $}'|grep-V' Use'|sed-E's/[%]//g') Do if[[$RemainingSpace > the]]; Then Echo-E"$RemainingSpace" Echo-E"$ (df-h | grep $RemainingSpace)">/service/script/. Harddiskwarning Mail-S"Disk Warning"WL . Harddiskwarningfi Done4. Detecting remaining Inode#!/bin/Bash#inspcet Inode
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.