\x20\40\x20\40 HEX
HEX
Server: Apache
System: Linux web1.jenscom.net 4.18.0-553.111.1.el8_10.x86_64 #1 SMP Sun Mar 8 20:06:07 EDT 2026 x86_64
User: sps (1059)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: //usr/libexec/kcare/migrations/migrate-cron-hour-randomize.sh
#!/bin/bash

set -eu -o pipefail

# Randomize auto-update hour to spread load across ePortal.
# Instead of all agents checking at */4 (0,4,8,12,16,20), randomly pick
# one of four hour-offset schedules to distribute requests evenly.

KCARE_CRONFILE=/etc/cron.d/kcare-cron

if [[ ! -f "$KCARE_CRONFILE" ]]; then
    exit 0
fi

if ! grep -qE '^[0-9]+[[:space:]]+\*/4[[:space:]]' "$KCARE_CRONFILE"; then
    exit 0
fi

case $(( RANDOM % 4 )) in
    0) HOURS='0,4,8,12,16,20' ;;
    1) HOURS='1,5,9,13,17,21' ;;
    2) HOURS='2,6,10,14,18,22' ;;
    3) HOURS='3,7,11,15,19,23' ;;
esac

sed -Ei 's/^([0-9]+[[:space:]]+)\*\/4([[:space:]])/\1'"$HOURS"'\2/' "$KCARE_CRONFILE"