Application practice of cyclic control and status return value (Analysis Apache log)

Source: Internet
Author: User
Tags apache log

The difference and contrast of 12.1 Break,continue,exit,return


Break and continue are used in conditional statements and loop statements (FOR,WHILE,IF, etc.) to control the direction of the program; Exit user terminates all statements and exits the current script, in addition, exit can return the execution state value of the last program or command to the current shell ; return is similar to exit, except that return is used only in the state value that is performed by the function return value function.

Break N if n is omitted, it jumps out of the entire loop, n indicates the number of layers jumping out of the loop

Continue n If you omit N, it means skipping the loop, omitting the remainder of this omitted code, entering the next loop of the loop, n means exiting the nth layer and continuing the loop

Exit N Launches the current shell program, n is the return value of the previous program execution, n can also be omitted, in the next shell through the "$?" Receives the n value of exit

Return n is used as the return value of a function in the function to determine whether the function is executed correctly


12.2 Break,continue,exit Function (summary above)

In the while and for

Break is used to exit the current loop statement, thinking that the loop ends

Continue is used to exit the current loop hierarchy and continue the next loop

Exit user exits the script directly, not executing the shell

Developing a shell script to temporarily configure multiple Ip,ip for the server is 192.168.116.150-192.168.116.160, but does not create 192.168.116.155

#!/bin/bash#ip:192.168.116.150-192.168.116.160a=150for i in ' seq "do if [$a-eq 155]; Then ((a++)) continue fi ip=192.168.116. " $a "ifconfig ens33: $i $ip netmask 255.255.255.0 up ((a++)) done

Analyze Apache access logs, add the number of fields corresponding to the number of bytes per row of data in the log, calculate the total amount of traffic, and give the implementation order, using the while loop structure.

#!/bin/bash#logfile=/var/log/httpd/access_logsum=0exec </var/log/httpd/access_logwhile read linedo# sum=0 b= ' echo "$line" |  awk ' {print $ a=$} '? Expr $a + 5 >/dev/null if [$-eq 0]; Then sum=$ (($sum + $b)) Fidoneecho $sum


Application practice of cyclic control and status return value (Analysis Apache log)

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.