Update cronjobs.sh
set to work also if in different folder structure and improved logging
This commit is contained in:
parent
ac82e9b5cc
commit
dd08482038
33
cronjobs.sh
33
cronjobs.sh
|
|
@ -1,21 +1,26 @@
|
|||
#!/bin/sh
|
||||
|
||||
echo "Starting Script $0"
|
||||
# Get the current date and time in a specific format
|
||||
formatted_time=$(date +"%Y-%m-%d %H:%M:%S")
|
||||
BASE_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
PHP_BIN="php"
|
||||
LOG_FILE="$BASE_DIR/cron.log"
|
||||
|
||||
# Echo the formatted time
|
||||
echo "Current time: $formatted_time"
|
||||
echo "=========================================" >> "$LOG_FILE"
|
||||
echo "CRON START $(date '+%Y-%m-%d %H:%M:%S')" >> "$LOG_FILE"
|
||||
echo "BASE_DIR: $BASE_DIR" >> "$LOG_FILE"
|
||||
|
||||
cd "$BASE_DIR" || { echo "cd failed: $BASE_DIR" >> "$LOG_FILE"; exit 1; }
|
||||
|
||||
cd domains
|
||||
cd zefix.silias.ch
|
||||
cd public_html
|
||||
/usr/bin/php taskExecuter.php
|
||||
echo "Script is Ending $0"
|
||||
start_ts=$(date +%s)
|
||||
|
||||
# Get the current date and time in a specific format
|
||||
formatted_time=$(date +"%Y-%m-%d %H:%M:%S")
|
||||
$PHP_BIN "$BASE_DIR/taskExecuter.php" >> "$LOG_FILE" 2>&1
|
||||
status=$?
|
||||
|
||||
# Echo the formatted time
|
||||
echo "Current time: $formatted_time"
|
||||
end_ts=$(date +%s)
|
||||
duration=$((end_ts - start_ts))
|
||||
|
||||
echo "Exit code: $status" >> "$LOG_FILE"
|
||||
echo "Duration: ${duration}s" >> "$LOG_FILE"
|
||||
echo "CRON END $(date '+%Y-%m-%d %H:%M:%S')" >> "$LOG_FILE"
|
||||
echo "" >> "$LOG_FILE"
|
||||
|
||||
exit $status
|
||||
Loading…
Reference in New Issue