#!/bin/bash
filename="memory-$(date +%d-%m-%y-%H_%M).log"
interval=10

echo "Starting memory logger background job..."

# The loop wrapped in parentheses running in the background
(
while true
do
    echo "$(date)" >> "$filename"
    #mariadb --socket=/secondary/data/mysql.sock  -N -e "source worker.sql;show global status like '%duck%';SELECT duckdb_query_udf('FROM duckdb_memory()')\G " >> "$filename"
    mariadb --socket=/secondary/data/mysql.sock  -e "source worker.sql;show global status like '%duck%';SELECT duckdb_query_udf('FROM duckdb_memory()')\G " >> "$filename"
    sleep $interval
done
) &

# Save the PID of the background process we just started
echo $! > pid.file
echo "Script started with PID $(cat pid.file). PID saved to pid.file."
