Checking cronjob syntax

Charlie Brune fedora at bruneworld.com
Tue Aug 28 01:11:08 UTC 2012


On 08/27/2012 01:44 AM, Sjoerd Mullender wrote:
> On 2012-08-27 08:39, Frank Murphy wrote:
>> Today being Monday:
>> 45 5 22-28 * * test 'date +\%A' = Sunday && yum -v clean plugins
>>
>> Nothing appears to have happened. (no email to root, usual cron stuff)
>> So taking the bit from "test" eg:
>> test 'date +\%A' = Sunday && blkid (all days in turn)
>> blkid doesn't run
>>
>> Where have I slipped up
>>
>>
> You're using the wrong quotes.  As it stands, your comparing the string
> "date +%A" with the string "Sunday".  Presumably what you want is to
> compare the output of the command "date +%S" with the string "Sunday".
> You need to use "backticks" for that:
> test `date +\%A` = Sunday
> You're not getting output because the test fails and so yum never gets
> executed.  All of that happens in silence, hence no mail to root.
> You can check you cron log /var/log/cron to see that the command did
> execute.
>
>
>
Not sure if this will help you ... but here's how I run my jobs on the 
first Sunday of the month.

23      1       1-7     *       *       [ `date +\%a` == "Sun" ] && 
/root/send-monthly-emails

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.fedoraproject.org/pipermail/users/attachments/20120827/3441e5ae/attachment-0001.html>


More information about the users mailing list