Exercise 1: Generate a file every day
Requirements: please generate a daily file according to the date format (XXXX-XX-XX), for example, the file generated today is 2018-02-05.log, and write the disk usage to this file (do not consider Cron, just write the script)
Reference Answer:
#!/bin/bash# date:2018 February 5 d= ' date +%f ' logname= ' $d. Log ' df-h >/tmp/$logname
Exercise 2: Statistical logs
Requirement: What is the number of visits per IP?
Log 1.log Fragment:
112.111.12.248-[25/sep/2013:16:08:31 +0800]formula-x.haotui.com "/seccode.php?update=0.5598″200″http:// Formula-x.haotui.com/registerbbs.php "" mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;) "
61.147.76.51-[25/sep/2013:16:08:31 +0800]xyzdiy.5d6d.com "/attach.php?aid=54&k=9c1&t=18&fid=9& Sid=z1″301″http://xy.5d.com/thread-1435-1-23.html "" mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;. NET CLR 1.1.4322;. NET CLR 2.0.50727) "
Reference Answer:
awk ' {print '} ' 1.log| Sort-n|uniq-c|sort-n
Shell exercises (i)