#!/bin/bash

# Path to the cameras.json file
CAMERAS_JSON="/var/www/html/admin/cameras.json"

# Path to the PHP script
PHP_SCRIPT="/path/to/processSecurityImagery.php"

# Check if cameras.json exists
if [ ! -f "$CAMERAS_JSON" ]; then
    echo "Error: cameras.json not found at $CAMERAS_JSON"
    exit 1
fi

# Extract camera names from cameras.json
CAMERAS=$(jq -r '.[] | .name' "$CAMERAS_JSON")

# Start an instance of the PHP script for each camera
for CAMERA in $CAMERAS; do
    echo "Starting process for camera: $CAMERA"
    php "$PHP_SCRIPT" "$CAMERA" &
done

# Wait for all background processes to complete
wait

echo "All cameras have been processed."
