From 278049a95b9f05d946310495bfdad3ca756641c2 Mon Sep 17 00:00:00 2001 From: Marcus Kammer Date: Sun, 5 Nov 2023 13:43:06 +0100 Subject: [PATCH] Import access.csv into sqlite3 db --- sbcl-nginx.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sbcl-nginx.yml b/sbcl-nginx.yml index 118b9e4..ad2375b 100644 --- a/sbcl-nginx.yml +++ b/sbcl-nginx.yml @@ -421,11 +421,17 @@ write_files: # Increase history limit set -g history-limit 50000 - - path: /home/cl/nginx_logs.sql + - path: /home/cl/access_logs.sql owner: 'cl:cl' defer: True content: | - CREATE TABLE nginx_logs ( + -- commands.sql + + -- Set the mode to CSV to properly import CSV files + .mode csv + + -- If the table doesn't exist, create it + CREATE TABLE IF NOT EXISTS access_logs ( timestamp TEXT, ip_address TEXT, remote_user TEXT, @@ -436,6 +442,9 @@ write_files: http_user_agent TEXT ); + -- Import the data into the 'access_logs' table + .import '/var/log/nginx/access.csv' access_logs + - path: /home/cl/setup_sbcl.sh owner: 'cl:cl' permission: '0755'