#!/bin/bash # Define log file path LOG_FILE="/media/scripts/lychee-sync.log" # Function to log messages log_message() { local timestamp=$(date +"%Y-%m-%d %H:%M:%S") echo "[$timestamp] $1" >> "$LOG_FILE" } # Function to log errors log_error() { local timestamp=$(date +"%Y-%m-%d %H:%M:%S") echo "[$timestamp] [ERROR] $1" >> "$LOG_FILE" } # Run the PHP command log_message "Running PHP command..." sudo -E -u www-data php /app/code/artisan lychee:sync /app/code/public/uploads/import/ >> "$LOG_FILE" 2>&1 php_exit_code=$? # Check if the PHP command succeeded if [ $php_exit_code -eq 0 ]; then log_message "PHP command executed successfully. Deleting files and folders..." # Delete all files and folders inside the directory rm -rf /app/code/public/uploads/import/* >> "$LOG_FILE" 2>&1 rm_exit_code=$? if [ $rm_exit_code -eq 0 ]; then log_message "Files and folders deleted successfully." else log_error "Error deleting files and folders. Exit code: $rm_exit_code" fi else log_error "Error executing PHP command. Exit code: $php_exit_code" fi # Exit the script exit 0