shell scripting basics

Learn about shell scripting basics, we have the largest and most updated shell scripting basics information on alibabacloud.com

CentOS6.8 x86_64bit shell scripting to simulate Nginx service startup and shutdown

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

The SED of Shell scripting learning

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

Shell Scripting Encryption

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

Shell Scripting Learning notes-functions

= (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

Shell Scripting Practices

: #! /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-

Shell Scripting Exercises

}69fib 650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/83/3A/wKioL1ds-AHzMGi6AACeHA28HgU614.jpg-wh_500x0-wm_3 -wmp_4-s_2750262765.jpg "title=" Fibonacci recursion. JPG "alt=" Wkiol1ds-ahzmgi6aaceha28hgu614.jpg-wh_50 "/>Vi. Fibonacci (Recursive)#!/bin/bashfunctionfib () 76{77localval=$178 localfiv_val1=079localfiv_val2=0 80localfiv_curr=081if[ $1-lt3];then82 echo183 Return84fi85letval--86 fiv_val1=$ (fib $val ) 87let val--88fiv_val2=$ (fib $val ) 89 letfiv_curr= $fiv _val1+ $fiv _val29

Ubuntu uses shell scripting to copy a class of files from all folders under the current folder to the same folder

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 Scripting Exercises

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

Shell Scripting Considerations

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

Basic practice of Shell scripting----Learn a little bit every day

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

Common commands and statements for Shell programming (scripting)

: 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

Linux Shell Scripting Raiders Review

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

Zabbix installing exception issues through shell scripting

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

Shell scripting counts multiple CPU utilization

, 0.0% siCpu2 : 0.5% us, 0.1% sy, 0.0% ni, 99.4% ID, 0.0% wa, 0.0% Hi, 0.0% siCpu3 : 0.4% us, 0.1% sy, 0.0% ni, 99.5% ID, 0.0% wa, 0.0% Hi, 0.0% siCpu4 : 0.3% us, 0.1% sy, 0.0% ni, 99.5% ID, 0.0% wa, 0.0% Hi, 0.0% siCpu5 : 0.3% us, 0.1% sy, 0.0% ni, 99.6% ID, 0.0% wa, 0.0% Hi, 0.0% siCpu6 : 0.3% us, 0.1% Sy, 0.0% NI, 99.6% ID, 0.0% wa, 0.0% Hi, 0.0% siCpu7 : 0.2% us, 0.1% sy, 0.0% ni, 99.7% ID , 0.0% wa, 0.0% hi, 0.0% si3. Save parameters for the curren

Linux OPS automation shell scripting gadget

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

Shell Scripting Exercises

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

Using shell scripting to ping Check network connectivity between the blade server and the primary server

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:

Getting Started with shell scripting--variables

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

Automating code deployment through shell scripting

; shell_unlock;;; *) usage;esac}main$1$2Test mode [[email protected] ~]$ Curl--head http://192.168.56.11/index.htmlHTTP/1.1 Okdate:mon, 09:42:23 Gmtse rver:apache/2.4.6 (CentOS) openssl/1.0.1e-fips php/5.4.16 mod_wsgi/3.4 Python/2.7.5last-modified:mon, 2016 09:39: Gmtetag: "17-538ff61ca0a00" accept-ranges:bytescontent-length:23content-type:text/html; Charset=utf-8[[email protected] ~]$ curl-s--head http://192.168.56.11/index.html|grep "$ OK" http/1.1 OK3. Rollback1. List rollback version 2. The

Shell Scripting Learning Guide [third to fourth] find and replace, text processing tools

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

Total Pages: 15 1 .... 9 10 11 12 13 .... 15 Go to: Go

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.