FixCronBug


#!/bin/sh

# Works around a cron bug in
# DD-WRT v24-sp2 (12/14/11) std - build 18007
# for Gateworks GW2358-4.

# This script was written by Stephan Seidl in 2012, no copyright is claimed.
# It is offered as-is, without any warranty.
# This script is in the public domain; do with it what you wish.

unset LANG LC_ALL
LC_ALL=C
export LC_ALL

test "`nvram get cron_enable`" = "1" || exit 0

# Remove the useless cron source.
rm -f /tmp/cron.d/cron_jobs

# Create file `/tmp/crontab' removing the `^M' seps.
touch /tmp/crontab
chmod 644 /tmp/crontab
nvram get cron_jobs | tr '\015' ' ' > /tmp/crontab

# Send SIGHUP to the cron process.
pid=`ps`
pid=`echo "${pid}" | grep cron`
pid=`echo "${pid}" | tr '\011' ' '`
pid=`echo "${pid}" | sed 's,^  *,,'`
pid=`echo "${pid}" | sed 's,  *$,,'`
pid=`echo "${pid}" | sed -n 's,  *cron$,,p'`
pid=`echo "${pid}" | cut -f1 -d' '`
nine="${pid}"
nine=`echo "${nine}" | tr '[0-8]' '999999999'`
nine=`echo "${nine}" | sed 's,^99*$,9,'`
test "${nine}" = "9" || pid="9999999999"
test "${pid}" = "9999999999" || kill -1 "${pid}"

exit 0


Stephan K.H. Seidl