(1st week) ____10 Road shell programming problems

[Time]: 2019-07-01 ~ 2019-07-07
[theme]: One week study summarizes
the main contents include 10 shell exercises, as a white, pure existence of theoretical knowledge and technology can not produce very knowledge deep impression, only in actual combat or continuous learning in practice, will have a deeper understanding of the knowledge points.
Haha

[Shell] practice summary

			关于shell编程题来源,可参考:https://www.cnblogs.com/clsn/p/8028337.html#auto_id_11

[First question]: shell game to achieve the drawing of lots

Requirements:
1. After executing the script, enter the name English spelling, numbers between 01-99 generate a random number, the greater the numerical score went to high numbers already caught, the next not appear in the same numbers.
2. Enter the first name, screen output, and record the names and numbers to a file, quit the program can not continue to wait for others to enter.
FIG follows:
lot
a reading requirement found necessary to achieve the required knowledge practice comprising: a random number generator; exit command modification 2; 3 font color modification; 4 console command input; 5 digital sorting commands......
A solution :
by reading the requirements, my own solution as follows:
lot

	**解法二:
	解法二是本题作者提供的答案,可参考连接https://www.cnblogs.com/clsn/p/8028337.html#auto_id_49 1.91 练习题答案。
	【总结】
	             对比和作者的解法,基本一致,但是作者对随机数封装成了一个函数,这样就可以产生复用的作用。把一个独立功能封装起来复用的思想指得反思。

[Second Title] 9 x 9 outputs the multiplication table

Requirements the following format:
Sample
Method One:
The author Solution:
9 * 9 multiplication table
Solution II:
Author answer:
9*9
[summary]
solution and the author of a comparison, I found the solution slightly complicated, in terms of ideology and a bit stupid. In fact, the main reason is to reflect the author forgotten echo -n usage: the output does not wrap. Before wrapping been tangled issue, so using "Quxianjiuguo" approach, each column generates a file, and then merge nine documents show.

[] The third problem to solve production DOS attack case

Requirements:
write a Shell script to solve the DOS attack
Please log or a web or network based on the number of connections, when a monitor or IP number of concurrent connections reaches 100 PV within a short time (the reader is set according to the actual situation), that the sealing of the corresponding call firewall command the IP. Firewall command: iptables-I INPUT -s IP address -j DROP.
Practice using log Download: https://files.cnblogs.com/files/clsn/access-web-log.zip
[a solution]:
After seeing this problem, I was a bit ignorant force, because usually work less Shiyun Wei comes to the real work, then access to information to understand: in fact, the sealing of those ip frequent access to the server end in a short time. Because the operation on a local virtual machine, so the authors to practice with the log.
FROM
Solution [two]:
From[summary]
comparison of the solution, found the author's solution is more concise, the authors used awk and advanced usage while, and I was piling up a lot of command. For comparison, the author's solution is more recommendable, but requires the use of awk have a higher understanding and use.

[Title] The fourth word and the letters to reorder

Requirements:
Frequency 1. Press descending order word appears;
frequency alphabetically descending order 2 appears.
As follows:
The Squid Project Number ofresources to the Provides A Users Assist Implement Design and Support The Squid installations.Please the Browse Sections Documentation and Support for Training More Infomation byoldboy

[Solution]
of this title is actually relatively simple solution:
Sequence[summary]
comparison of the solution, basically the same, because this question basically ordering the use of shell commands, it is relatively simple.

[Title] The fifth volume generated random character file name

Requirements:
Batch 10 to create html files in the current directory of ./clsn for loop, wherein each of the file needs to contain 10 random lowercase string plus fixed CLSN, name example:
Sample
[Method A]:
this question In fact, the main difficulty is how to generate 10 random string, I solution as follows:
random
[Solution 2]:
random
[summary]
comparison of writing, the author encapsulates a random character generation function Suiji, and the author is generated command to install a random character -pwgen . Way more simple, it is worth learning. And even if the author do not pwgen command, the authors named File_name variable length can be generated as random characters 10! This is praise!

[Title] The sixth batch rename special cases

Requirements:
[Title] result clsn fifth string in the file name all into znix (preferably implemented for loop), and the extension html into all uppercase.

[A] solution:
This question test sites mainly in how to intercept a string. I solution as follows:
Renamed[Solution two]
aaa[summary]
comparison of the solution, I use the conventional way to intercept the file name, and the author using sed regular matching high-end approach, although I think they are writing more concise and easy to understand, but on the use of regularization worth learning! great!

[Q7] requires the user to create a special batch

Requirements:
batch create 10 clsn01-clsn10 system account and set a password (the password is a random number, requires mixing characters and numbers, etc.).
As shown below:
create

[A] solution
Add the user name
[Solution two]
aaaaa
[summary]
comparison of writing, the author did not take into account if a user deleted an existing user to learn and re-create it. Also to be noted is that the authors are using the root user execute the script, the writer script is executed again under ordinary users.

[Q8] scan the network host memory alive

Requirements:
judge 10.0.0.0/24 network, currently online IP What?

check[Method A]
This question test sites primarily ping of use:
[Solution 2]:
Here Insert Picture Description
[summary]
I solution basic and the same authors, the parameters used this question endpoint study ping, the detailed use ping, refer to: HTTPS: // Blog. csdn.net/gechong123/article/details/80609598

[Title] ninth to break a random number RANDOM

Requirements:
known string by the following five variables md5sum random number RANDOM After again extracting the most significant part of a continuous string, the corresponding front RANDOM break character string corresponding to the digital processing using these md5sum?
21029299 00205d1c a3da1677 1f6d12dd 890684b

[Solution A]
using the question test sites md5sum command and the scope of random of [0 ~ 32767], I Solution follows:
Crack
[Solution two]
aaaaa
[summary]
This problem solving ideology of random liters into each random number as a md5sum, then find the number comprising at least a continuous string. And a solution of contrast, the code is relatively simple and a little author. But the authors of the code is easier in understanding.

[Q10] blog Bowen reptile park

Requirements:
acquiring blog Park (pathetic state juvenile) blog list and in accordance with article reverse sort, format below:
crawl
[a solution]:
crawl
[two] Solution:
As the author commissioning of the code did not run successfully, do not stick out interested can visit: https://www.cnblogs.com/clsn/p/8028337.html#auto_id_12 [1.2.7] exercises
[summary]
feeling shell has many limitations in terms of reptiles, although the nature of both It parses the text, but I also recommend python in terms of reptiles.

================================================== ================================================== =====
week learning about the contents of the shell so much, hey, like the python week's exercises are also posted, but should go out to buy food to cook it.
Next week to continue their efforts! Come on! !
smile

Released eight original articles · won praise 6 · views 2528

Guess you like

Origin blog.csdn.net/weixin_42374329/article/details/95007450