adding logging
This commit is contained in:
parent
3d093d1a39
commit
dcbc4d9408
|
@ -1,10 +1,36 @@
|
||||||
#!/bin/bash
|
#!/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
|
# Run the PHP command
|
||||||
php /app/code/artisan lychee:sync /app/code/public/uploads/import/
|
log_message "Running PHP command..."
|
||||||
|
php /app/code/artisan lychee:sync /app/code/public/uploads/import/ >> "$LOG_FILE" 2>&1
|
||||||
|
php_exit_code=$?
|
||||||
|
|
||||||
# Check if the PHP command succeeded
|
# Check if the PHP command succeeded
|
||||||
if [ $? -eq 0 ]; then
|
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
|
# Delete all files and folders inside the directory
|
||||||
rm -rf /app/code/public/uploads/import/*
|
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
|
fi
|
||||||
|
|
Loading…
Reference in New Issue