#!/bin/bash
# panel-cron-run <domain> <script inside docroot> [args]  — run a site cron with low priority, a hard timeout and errors logged
d="$1"; s="$2"; shift 2
u=$(id -un); root="/home/$u/public_html/$d"
log="/home/$u/logs/cron-errors.log"
[ -f "$root/$s" ] || { echo "$(date -u '+%F %T') NOT FOUND $d/$s" >> "$log"; exit 1; }
cd "$(dirname "$root/$s")" || exit 1
exec nice -n 10 timeout 290 /usr/bin/php -d memory_limit=512M "$(basename "$s")" "$@" > /dev/null 2> >(sed "s|^|$(date -u '+%F %T') $d: |" >> "$log")
