Shell script simulates Nginx service startup and shutdownNote: 3 slashes////is followed by a representation of the interpretation of the current statement, which must be removed in the actual script#!/bin/bash///defines which scripting language interprets the following statement[-f/etc/init.d/functions]. /etc/init.d/functions///Judge and load system functionsnginx= "/application/nginx/sbin/nginx"///nginx Se
file from line 22nd to line 33rd to the end of line 44th.
Sed ' 1,21h;22h;23,33h;44g ' pass
18, move the file from line 22nd to line 33rd to the end of line 44th.
Sed ' 22{h;d};23,33{h;d};44g ' pass
19, only the first word of each line is displayed.
Sed-nr ' s/([^a-z]*) ([a-z]+) ([^a-z]+] (. *)/\2/p '/etc/passwd
20, print the first word and the third word of each line.
Sed-nr ' s/([^a-z]*) ([a-z]+] ([^a-z]+) ([a-z]+] ([^a-z]+) ([a-z]+] (. *)/\2
Think of a long time not updated blog, today in the group to see the discussion about shell script encryption things.Think about it too, we are writing scripts sometimes configure the relevant account and password things, so as long as the permission can see the information, very insecure, there is no normal operation of the file encryption. The following two features are broadly available:
Encrypt files to prevent others from seeing what I w
= (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
: #! /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
and so on one by one corresponds; case $MENU In Jiaozi) The echo "Your Choose is $REPLY" # # variable REPLY dedicated to storing the results of user input echo "$MEN
U Price is 20 ";;
Lamian) echo "Your Choose is $REPLY" Echoes "$MENU Price is 15";;
Mifan) echo "Your Choose is $REPLY" Echoes "$MENU Price is 18";;
Daoxiaomian) echo "Your Choose is $REPLY" Echoes "$MENU Price is 12";;
Quit) echo "Your Choose is $REPLY" break;;
*) echo "Your Choose is $REPLY" echo "Choose a
In order to check the network connection status between the daq01 and the blade server,1. Use the output rule of ping command, if can ping pass, will output 0% packet loss value; If you cannot ping the pass, the 0% packet loss is not output2. If the ping command output 0% packet loss successful execution, the network connection is OK, otherwise the network connection is not3. in Shell scripts | | For use, refer to 20360107Command1 Command2Indicates:
content such as/boot is a specific content)$?: The state returned after the previous command was executed, when the return status value is 0 indicates normal execution, and a value other than 0 indicates an exception or errorDetermine if an error occurs correctly for 0 exception error for non 0 value between 1-127$: The currently executing process/program name (which is the name of the currently executing command or program)Tip: Add Environment variablesVim/etc/profileAt the end of the document
Summary: Chapter Three discusses the two basic operations that are commonly used when writing shell scripts. The fourth chapter introduces about 30 useful tools for processing text files.Chapter III Find and replaceSummary: This chapter discusses the two basic operations that are commonly used when writing shell scripts: text lookup, text substitution.3.1 Finding textTo remove a specific line of text from t
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.