Unix challenges

Have fun! Submit new challenges and solutions to old ones to unix@current_domain. You should replace current_domain with enpo.no :)

Challenge 1: When is httpd the most busy?

2018-08-26 19:23:30 — Adrian Kjær Dalhaug

We must find the minute with the most bytes tranferred. Read from ./input.txt.

Input example


in24.inetnebr.com - - [01/Aug/1995:00:00:01 -0400] "GET /shuttle/missions/sts-68/news/sts-68-mcc-05.txt HTTP/1.0" 200 1839

The bytes transferred is the last field on each line. In this case: 1839 bytes.

Output format


date_string_with_minute_precision bytes_transferred

Example output


01/Aug/1995:00:18 84688

Challenge 2: Find weekday of date

2018-08-26 19:25:37 — Adrian Kjær Dalhaug

By providing a date on format YYYY-MM-DD, the program should output the weekday as an integer from 1-7 (1=Monday, 7=Sunday).

Example


$ ./solution.sh 2018-01-01
1

Challenge 3: Precision and timezone

2018-08-26 19:30:10 — Adrian Kjær Dalhaug
  • Remove milliseconds from timestamp (column 3).
  • Change from the timezone from -07:00 to UTC (column 2 and 3).
  • Zero pad the hour (column 3). Example: From 7:10:03 -> 07:10:03.

Data in ./input.txt.

Example input.txt


1,2017-10-01,20:29:53.000,24-73-E3-A6-7C-A5
2,2017-11-02,22:48:40.000,08-BC-C4-91-A2-B1
3,2018-07-28,13:08:03.000,55-53-56-70-93-A1
4,2018-06-14,1:54:51.000,EB-81-FD-8A-26-63
5,2018-07-22,22:35:19.000,28-15-35-79-92-DD

Example output


1,2017-10-02,03:29:53,24-73-E3-A6-7C-A5
2,2017-11-03,05:48:40,08-BC-C4-91-A2-B1
3,2018-07-28,20:08:03,55-53-56-70-93-A1
4,2018-06-14,08:54:51,EB-81-FD-8A-26-63
5,2018-07-23,05:35:19,28-15-35-79-92-DD

Challenge 4: Common IPs

2018-08-26 19:32:50 — Adrian Kjær Dalhaug

Print the IPs/hostnames that appear in both ./input1.txt and ./input2.txt. The IP or hostname is the first field on each line.

Input example


131.235.117.31 - - [01/Aug/1995:00:16:17 -0400] "GET /icons/blank.xbm HTTP/1.0" 200 509
ad10-015.compuserve.com - - [01/Aug/1995:00:16:43 -0400] "GET /shuttle/missions/51-l/mission-51-l.html HTTP/1.0" 200 6658