#!/bin/sh ################################################################################ # A utility function to convert an HTTP log stdin into CSV and pipe its output # # to sqlite-utils for easy querying # # # # NOTE: It requires the `sqlite-utils` command-line tool to be installed. # # Install it with `pip install sqlite-utils` # # # # @author: Fabio Manganiello # # @license: MIT # ################################################################################ query-http-log() { if [[ -z "$1" ]]; then echo "Usage: [cat|head|tail] /var/log/nginx/[logfile] | query-http-log [extra args for sqlite-utils]" echo "" echo "Example: cat /var/log/nginx/access.log | query-http-log \"select * from stdin where response_code = 404 and date > '2023-01-01\' limit 10" return 1 fi cat <