>_ IzzyLab

Hands-on task

This task is step 6 of the course “Logs: analysis and housekeeping”

Migration output from a deploy log

medium~5 min

In the deploy log /var/log/deploy/run.log the database migration output is wrapped in the lines >>> migrations begin and <<< migrations end. Save to /root/migrations.txt only the lines inside the block — without the markers themselves and without anything before or after.

What you'll practise:
  • awk
  • state flag
  • next
  • block between markers

Topic breakdown

Cutting a piece of a log between two markers is a stateful task: for every line you need to know whether you are inside the block or outside. In awk this is a flag variable that the start line switches on and the end line switches off. The order of the rules decides whether the markers end up in the output: next after switching on skips printing the start marker, and resetting the flag before the print rule keeps the end marker out. A bare pattern without an action in awk means "print the line if the expression is true".

What's checked

  1. /root/migrations.txt has only the migration lines

What it looks like