Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 493706

Summary: sys-fs/mdadm-3.3-r2 - cron.d entry for checkarray is incompatible with sys-process/dcron, causing error emails
Product: Gentoo Linux Reporter: Hank Leininger <hlein>
Component: [OLD] Core systemAssignee: Gentoo's Team for Core System packages <base-system>
Status: RESOLVED FIXED    
Severity: normal CC: cron-bugs+disabled
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description Hank Leininger 2013-12-09 03:48:18 UTC
sys-fs/mdadm-3.3-r2 started installing checkarray from the debian patchset, and also added an entry to /etc/cron.d/ to run it.

The format of the Debian-based mdadm.cron.d file breaks on (at least) dcron.

The file contains:

57 0 * * 0 root if [ -x /usr/sbin/checkarray ] && [ $(date +\%d) -le 7 ]; then /usr/sbin/checkarray --cron --all --idle --quiet; fi

...But in dcron, /etc/cron.d/ files are always jobs run by root, so there is no field for the username.  It looks to me like vixie cron (at least) does support the uername field in cron.d entries.

Reproducible: Always

Steps to Reproduce:
1. Use dcron as the cron daemon.
2. Upgrade to sys-fs/mdadm-3.3-r2 
3. Get error emails once a week from cron
Actual Results:  
Every week when the job runs, get this parse error email:

Date: Sun, 08 Dec 2013 00:58:01 -0500
From: root <root@box>
To: root
Subject: cron for user root root if [ -x /usr/sbin/checkarray ] && [ $(date +\%d) -le 7 ]; then /usr/sbin/checkarray --cron --all --idle --quiet; fi

/bin/sh: -c: line 0: syntax error near unexpected token `then'
/bin/sh: -c: line 0: `root if [ -x /usr/sbin/checkarray ] && [ $(date +\%d) -le 7 ]; then /usr/sbin/checkarray --cron --all --idle --quiet; fi'


Expected Results:  
The line should have parsed correctly, the if test should have executed properly, and either run or not run checkarray.

I'm not sure what the correct fix is, except perhaps recreate this one-liner as a /etc/cron.weekly/ file, because those files' format do not depend on what cron daemon is in use (they just get executed by run-crons, or run-parts, or whatever).

The /etc/cron.weekly/ file would be really really simple, and should accomplish exactly what the cron.d/ file does:

#!/bin/sh

if [ -x /usr/sbin/checkarray ] && [ $(date +\%d) -le 7 ]; then
  /usr/sbin/checkarray --cron --all --idle --quiet
fi
Comment 1 SpanKY gentoo-dev 2013-12-16 05:34:36 UTC
should be all set now in the tree; thanks for the report!

Commit message: Tweak cron.d entry to work for all crons
http://sources.gentoo.org/sys-fs/mdadm/mdadm-3.3-r2.ebuild?r1=1.1&r2=1.2
Comment 2 Mike Gilbert gentoo-dev 2014-07-12 20:13:12 UTC
(In reply to SpanKY from comment #1)

This broke the cron.d file for cronie (and probably vixie as well). The username field is requried in a system cron job.
Comment 3 Hank Leininger 2014-07-12 20:18:06 UTC
> This broke the cron.d file for cronie (and probably vixie as well). The
> username field is requried in a system cron job.

Argh, so different cron's have different syntaxies for /etc/cron.d/ entries?  Sigh.

Do you know if my alternate suggestion, turning it into a cron.weekly/ script, will work across those other crond's?  (Assuming most/all crons supported by Gentoo include the moving parts to run /etc/cron.weekly/ scripts.)
Comment 4 Mike Gilbert gentoo-dev 2014-07-12 20:28:04 UTC
Yes, I think cron.weekly will be fine.

+*mdadm-3.3-r4 (12 Jul 2014)
+
+  12 Jul 2014; Mike Gilbert <floppym@gentoo.org> +files/mdadm.weekly,
+  +mdadm-3.3-r4.ebuild:
+  Replace cron.d file with a cron.weekly script, disabled by default. Bug
+  493706.