diff --git a/modules/website/wordpress/wordpress-cron-manager.sh b/modules/website/wordpress/wordpress-cron-manager.sh index 03bf853..9d7fdbf 100755 --- a/modules/website/wordpress/wordpress-cron-manager.sh +++ b/modules/website/wordpress/wordpress-cron-manager.sh @@ -31,9 +31,10 @@ fi trap 'flock -u 9; rm -f "$LOCK_FILE"' EXIT INT TERM # OPTIMIZATION: Parse command-line flags for script behavior -# Support: --dry-run, --parallel, --help +# Support: --dry-run, --parallel, --log, --help DRY_RUN=false ENABLE_PARALLEL=false +LOG_OUTPUT_FILE="" for arg in "$@"; do case "$arg" in @@ -43,17 +44,45 @@ for arg in "$@"; do --parallel) ENABLE_PARALLEL=true ;; + --log) + # Next argument should be the log file path + # Will be set in the next iteration or default to /tmp + LOG_OUTPUT_FILE="/tmp/wordpress-cron-manager-$(date +%Y%m%d-%H%M%S).log" + ;; + --log=*) + # Handle --log=/path/to/file format + LOG_OUTPUT_FILE="${arg#--log=}" + ;; --help) echo "Usage: $0 [OPTIONS]" + echo "" echo "Options:" - echo " --dry-run Run in dry-run mode (no actual changes)" - echo " --parallel Enable parallel processing for multi-site ops" - echo " --help Show this help message" + echo " --dry-run Run in dry-run mode (no actual changes)" + echo " --parallel Enable parallel processing for multi-site ops" + echo " --log [FILE] Enable logging to file (default: /tmp/wordpress-cron-manager-TIMESTAMP.log)" + echo " --log=/path/to/file Log to specific file path" + echo " --help Show this help message" + echo "" + echo "Examples:" + echo " $0 --dry-run --parallel" + echo " $0 --log" + echo " $0 --log=/var/log/wp-cron-conversion.log" exit 0 ;; esac done +# Initialize logging if --log flag was used +if [ -n "$LOG_OUTPUT_FILE" ]; then + LOG_ENABLED=true + LOG_FILE="$LOG_OUTPUT_FILE" + # Ensure log file is writable + if ! touch "$LOG_FILE" 2>/dev/null; then + echo "ERROR: Cannot write to log file: $LOG_FILE" >&2 + LOG_ENABLED=false + fi +fi + # PHP binary path detection PHP_BIN=$(command -v php 2>/dev/null || echo "/usr/bin/php")