Needle in the Haystack
Tasks
- Find all ERROR messages in the file
/home/labex/project/system.log
and count how many there are.
- Find all lines containing POST requests in the file
/home/labex/project/access.log
.
- Find all lines in
/home/labex/project/application.log
that contain both "WARNING" and "query" (case-insensitive).
- Search for all user authentications (containing "User authenticated") across all log files.
Requirements
- All operations must be performed in the
/home/labex/project/
directory.
- Use the
grep
command for all search operations. You may use other commands in combination with grep
if necessary (e.g., wc
).
- For each task, create a file with the output of your command(s). Name the files
task1_output.txt
, task2_output.txt
, task3_output.txt
, and task4_output.txt
respectively.
- Do not modify the original log files.
Example
Here's an example of how your command and output might look:
$ cat task1_output.txt
123
$ head -n 2 task2_output.txt
192.168.1.105 - - [13/Aug/2023:10:55:36 +0000] "POST /api/v1/order HTTP/1.1" 201 354
192.168.1.106 - - [13/Aug/2023:10:56:12 +0000] "POST /api/v1/user HTTP/1.1" 200 128
$ head -n 2 task3_output.txt
2024-05-22 09:55:35 WARNING Database query timeout: SELECT * FROM users WHERE id = 906
2023-09-26 09:55:35 WARNING Slow query detected. Execution time: 2116ms
$ head -n 2 task4_output.txt
system.log:2024-03-27 09:55:32 INFO User authenticated: user67
system.log:2024-03-10 09:55:32 INFO User authenticated: user60
Note: The actual content may be different in your log files.