Shell Exercises (ix)

Source: Internet
Author: User

Exercise 1:Find patterns to print numbers

Requirements: Please review the rules of the following numbers in detail and use the shell script to output the following 10 digits.
10 31 53 77 105 141 .....

Hint: The difference between the two adjacent numbers has a regular value

Reference Answer:


Exercise 2: IP-blocking

Requirements: according to the access log on the Web server, some high-volume IP is rejected!

Analysis: What we want to do is not only to find out which IP requests are illegal, but also to unpack the IP that was previously blocked (if requested again) at every other time. So the key point of the script is to set a suitable time period and threshold value.

For example, we can check the log every minute, the last minute of the log to filter out the analysis, and as long as the number of IP requests more than 100 times then directly sealed off. And the time of the solution is also stipulated for every half-hour analysis, the almost no request volume of IP to the solution!

Reference log file Fragment:

137.23.21.127 [20/jan/2018:00:01:24 +0800] www.testbbs.com "/bbs/thread-5622-3-1.html" "-" "mozilla/5.0 ( Compatible bingbot/2.0; +http://www.bing.com/bingbot.htm) "

54.124.50.87 [20/jan/2018:00:01:34 +0800] www.testbbs.com "/bbs/search.php?mod=forum&srchtxt=lnmp&formhash "=8f0c7da9&searchsubmit=true&source=hotsearch"-"mozilla/5.0" (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm) "

Reference Answer:


Exercise 3: monitoring the HTTPD process

requirements: on the server, write a monitoring script.

1. Every 10s to detect the number of httpd processes on the server, if greater than or equal to 500, you need to automatically restart the Apache service, and detect the success of the launch?

2. If there is no normal boot and need to start again, the maximum number of unsuccessful more than 5 times you need to understand the email notification to the administrator, and do not need to detect again!

3. If the start is successful, after 1 minutes to re-detect the number of httpd process, if normal repeat the previous operation (every 10s detection), if it is greater than or equal to 500, then discard the restart and need to send an email to the administrator, and then automatically exit the script. Send mail script as before mail.py

Reference Answer:



"The answer will be announced before 12 o'clock noon tomorrow!" 】

Shell Exercises (ix)

Related Article

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.