cron usage

Isaac Dunham ibid.ag at gmail.com
Sat Jan 9 05:10:21 UTC 2016


On Fri, Jan 08, 2016 at 03:15:05PM -0500, David Henderson wrote:
> >
> > Hi,
> >
> > //config:	help
> > //config:	  Crond is a background daemon that parses individual crontab
> > //config:	  files and executes commands on behalf of the users in question.
> > //config:	  This is a port of dcron from slackware. It uses files of the
> > //config:	  format /var/spool/cron/crontabs/<username> files, for example:
> > //config:	      $ cat /var/spool/cron/crontabs/root
> > //config:	      # Run daily cron jobs at 4:40 every day:
> > //config:	      40 4 * * * /etc/cron/daily > /dev/null 2>&1
> >
> > Ciao,
> > Tito
> 
> Thanks for the reply Tito!  So does the -c parameter change the
> parsing directory from /var/spool/cron/crontabs, or does it specify a
> 'holding' directory for the individual cron jobs?  Also, does that
> mean that I can't implement something like an /etc/cron.d directory
> where any cron jobs within it are parsed, or can I create an
> /etc/crontab file to parse that directory using run-parts?


Busybox crond does not support /etc/crontab.
run-parts runs all scripts in a directory, rather than providing a way to
parse all files within it.

Now, here's a script that should add all /etc/cron.d/* jobs with proper
permissions to the right crontabs (assuming it works right; NOT TESTED!):

#!/bin/busybox ash

other_writeable () {
	MODE=`stat -c %05a "$1"` || return 1
	MODEG=`echo $MODE | cut -c 4`
	MODEO=`echo $MODE | cut -c 5`
	# if mode is 2-3 or 6+ (writeable bit is set), return 0
	test $MODEG -gt 1 -a $MODEG -lt 4 || test $MODEG -gt 5 || \
	test $MODEO -gt 1 -a $MODEG -lt 4 || test $MODEO -gt 5 || \
	return 0
	# not writeable
	return 1
}

{
  for F in /etc/cron.d/*
    do
      other_writeable "$F" || cat "$F"
    done
} | grep -v '^#' | {
  while read MIN H DOM MON DOW U EXEC
    do
      echo "$MIN $H $DOM $MON $DOW $EXEC" >> /var/spool/cron/crontabs/"$U"
    done
}

Bear in mind that this script is a one-shot conversion tool; you would need
to remove duplicates manually if you ran it automatically, and there's
no rovision for removing cron jobs.

HTH,
Isaac Dunham


More information about the busybox mailing list