Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Shell problem set-22

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Topic requirement

Write a shell script to determine whether the website you are visiting is normal by the status code returned by curl-I.

For example, it is normal when the status code is 200.

Reference answer #! / bin/bash# this script is used to determine whether a URL is normal # author: ape lesson-A Ming www.apelearn.com# date: 2018-11-01 url = "http://www.apelearn.com/index.php"mail_user=306798658@qq.comcode=`curl-I $url 2 > / tmp/curl.err | head-1 | awk'{print $2} '`if [- z" $code "] then python mail.py $mail_user" $url access exception "`url / Tmp/ curl.err` "exitelif [$code! =" 200"] then curl-I $url & > / tmp/curl.log python mail.py $mail_user "$url access exception status code $code"`/ tmp/ curl.log`" fi title requirements

Package files smaller than 5KB under the user's home directory (considering that the user executing the script may be an ordinary user or a root) into a tar.gz package with the current date as the file name prefix, for example, 2018-03-15.tar.gz.

Reference answer

Check the file tar-tf tar.gz in the tar package

#! / bin/bash# this script is used to package files less than 5k in the user's home directory # author: ape lesson-A Ming www.apelearn.com# date: 2018-11-01t = `date +% F`cd $HOMEtar czf $t.tar.gz `date. /-type f-size-5k | xargs` topic requirements

A classmate accidentally blocked sshd port 22 with iptables rules and could not log in remotely. If you want to solve this problem, you have to go to the computer room and log on to the real machine to delete this rule. The problem is to write a monitoring script to monitor whether port 22 is blocked by the iptables rule, and if so, open it. Write a script, put it in the task plan, and execute it every minute.

Reference answer #! / bin/bash# this script is used to unblock port 22 # author: ape lesson-A Ming www.apelearn.com# date: 2018-11-01iptables-nvL INPUT-- line-numbers | grep-w 'dpt:22' | awk'$4 ~ / REJECT | DROP/ {print $1}'> / tmp/iptables.logn= `wc-l / tmp/iptables.log `if [$n-gt 0] then for n in `tac / tmp/ iptables.log` do iptables-D INPUT $n donefi title requirements

It is known that the log files accessed by nginx are in / usr/local/nginx/logs/access.log. Please count which ip visited most from 10:00 to 12:00 in the morning?

Reference log 111.199.186.68-[15/Sep/2017:09:58:37 + 0800] "/ / plugin.php?id=security:job" 200 "POST / / plugin.php?id=security:job HTTP/1.1"http://a.lishiming.net/forum.php?mod=viewthread&tid=11338&extra=page%3D1%26filter%3Dauthor%26orderby%3Ddateline"" Mozilla/5.0 (Windows NT WOW64) AppleWebKit/537.36 (KHTML Like Gecko) Chrome/61.0.3141.7 Safari/537.36 "203.208.60.208-[15/Sep/2017:09:58:46 + 0800]" / misc.php?mod=patch&action=ipnotice&_r=0.05560809863330207&inajax=1&ajaxtarget=ip_notice "200" GET / misc.php?mod=patch&action=ipnotice&_r=0.05560809863330207&inajax=1&ajaxtarget=ip_notice HTTP/1.1 "http://a.lishiming.net/forum.php?mod=forumdisplay&fid=65&filter=author&orderby=dateline"" Mozilla/5.0 (Windows NT WOW64) AppleWebKit/537.36 (KHTML Like Gecko) Chrome/61.0.3141.7 Safari/537.36 "reference answer #! / bin/bash# this script is used to analyze the Nginx access log # author: ape lesson-A Ming www.apelearn.com# date: 2018-11-01 www.apelearn.com# / definition of voice as English export LANG=enlog=" / usr/local/nginx/logs/access.log "# time definition 1 [01]: [0-5] [0-9]: t = `date +% dmax% B/%Y:1 [01]: [0-5] [0-9]: `egrep "$t" $log | awk'{print $1}'| sort-n | uniq-c | sort-n | tail-1 | awk'{print $2} 'topic requirements

Write a shell script. Prompt for a paused number and print from 1 to that number. Then ask if you want to continue. If you continue, enter another number and then print, otherwise exit the script.

Example: if the input is 5, print 1 2 3 4 5, then continue to enter 15, and then print 6 7. 14 15, and so on.

Reference answer #! / bin/bash# this script is used to print numbers # author: ape lesson-A Ming www.apelearn.com# date: 2018-11-0 enter a number read-p "Please input a number:" n # exclude the pure number N1 = `echo $n | sed's / [0-9] / / g '`if [- n "$N1"] then echo "Please input a number." Exitfifor i in `seq 1$ n`do echo $idone# whether to continue printing read-p "If continue? YBO" ccase $c in n | N) exit;; y | Y) # enter the number read-p "Please input a number for the second time:" N2 # determine whether it is a pure number n3 = `echo $N2 | sed's / [0-9] / / g '`if [- n "$n3"] then echo "Please input a number." Exit fi # determines whether the second number is greater than the first number if [$N2-le $n] then echo "$N2 should grater than $n." Exit fi for i in `seq $[$nq1] $n2` do echo $I done;; *) echo "Please input y or n."; esac

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report