#!/bin/bash # Function to run the command run_command() { python manage.py ingester & PID=$! echo "Started process with PID: $PID" } # Function to terminate the command interrupt_command() { kill -SIGINT $PID echo "Interrupted process with PID: $PID" } # Run the command initially run_command # Loop to restart the command every 2 hours until ingester_done.flag is found while [ ! -f ingester_done.flag ]; do # Wait for 2 hours (7200 seconds) sleep 7200 # Terminate the command interrupt_command # Restart the command run_command done echo "ingester_done.flag found. Exiting script."