2023-07-09 19:09:56 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-07-09 19:20:29 +00:00
|
|
|
# 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"
|
|
|
|
}
|
|
|
|
|
2023-07-09 19:09:56 +00:00
|
|
|
# Run the PHP command
|
2023-07-09 19:20:29 +00:00
|
|
|
log_message "Running PHP command..."
|
|
|
|
php /app/code/artisan lychee:sync /app/code/public/uploads/import/ >> "$LOG_FILE" 2>&1
|
|
|
|
php_exit_code=$?
|
2023-07-09 19:09:56 +00:00
|
|
|
|
|
|
|
# Check if the PHP command succeeded
|
2023-07-09 19:20:29 +00:00
|
|
|
if [ $php_exit_code -eq 0 ]; then
|
|
|
|
log_message "PHP command executed successfully. Deleting files and folders..."
|
2023-07-09 19:09:56 +00:00
|
|
|
# Delete all files and folders inside the directory
|
2023-07-09 19:20:29 +00:00
|
|
|
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"
|
2023-07-09 19:09:56 +00:00
|
|
|
fi
|