BASH SCRIPTING PROJECT · ABOUT 40 MIN · +150 XP
Log analyser script
Support keeps asking 'how bad is the app log today?'. Write a script they can run themselves.
Your tasks
- Create ~/bin/logstat.sh starting with #!/bin/bash and set -euo pipefail.
- If it's run without an argument, print Usage: logstat.sh FILE and exit with code 2.
- If the file doesn't exist, print No such file: followed by the name and exit with code 1.
- Otherwise print two lines: Total: N (number of lines) and Errors: M (lines containing ERROR).
- Make it executable and try it on /var/log/app/app.log.
Stuck? Every step is covered in the Bash Scripting lessons.