The expectation was that there would be a mailto attribute, but the this source denies that

cron { 'resource title':
  name        => # (namevar) The symbolic name of the cron job.  This name is 
  ensure      => # The basic property that the resource should be...
  command     => # The command to execute in the cron job.  The...
  environment => # Any environment settings associated with this...
  hour        => # The hour at which to run the cron job. Optional; 
  minute      => # The minute at which to run the cron job...
  month       => # The month of the year.  Optional; if specified...
  monthday    => # The day of the month on which to run the...
  provider    => # The specific backend to use for this `cron...
  special     => # A special value such as 'reboot' or 'annually'...
  target      => # The name of the crontab file in which the cron...
  user        => # The user who owns the cron job.  This user must...
  weekday     => # The weekday on which to run the command...
  # ...plus any applicable metaparameters.

The docs does not indicate if mailto is supported, e.g.:


(Property: This attribute represents concrete state on the target system.)

Any environment settings associated with this cron job. They will be stored between the header and the job in the crontab. There can be no guarantees that other, earlier settings will not also affect a given cron job.

Also, Puppet cannot automatically determine whether an existing, unmanaged environment setting is associated with a given cron job. If you already have cron jobs with environment settings, then Puppet will keep those settings in the same place in the file, but will not associate them with a specific job.

Settings should be specified exactly as they should appear in the crontab, e.g., PATH=/bin:/usr/bin:/usr/sbin.


The built-in Puppet type cron as referenced in the question has a property named environment that can be used to set environment variables for the managed cronjob.

In this case it would look like this, setting the MAILTO variable to foobar so that output of the cronjob will be mailed to user foobar:

cron { 'some-cron-job':
  environment => 'MAILTO=foobar',

You can use a module from puppet forge to manage cron and add environment variables to the cron job. I've used this one, there may be others.

You can do this

cron::job {
    minute      => '40',
    hour        => '2',
    date        => '*',
    month       => '*',
    weekday     => '*',
    user        => 'root',
    command     => 'mysqldump -u root mydb',
    environment => [ 'MAILTO=root', 'PATH="/usr/bin:/bin"' ];

Which among other things sets the MAILTO and PATH environment variables.

  • 4
    There is no need to use a special module just to be able to set environment variables for a cron job. The built-in cron type, as referenced in the question, has a parameter environment for this exact purpose. – daff May 25 '16 at 22:50
  • @daff Please transform this comment into an answer so I could accept it – 030 May 26 '16 at 7:55
  • @daff Confirmed that it works – 030 May 26 '16 at 8:03
  • @Alfred, ok will do! – daff May 26 '16 at 13:06
  • @daff I use that module for other reasons and sadly ASSuMEd that the OP had at least read the docs before posting :( – user9517 May 26 '16 at 14:31

cron sends output to the user running the job. If you want to redirect the mail there are a few options.

  • Handle the output and mailing in the script running the job.
  • Use an entry in the email aliases file to redirect the output. This will redirect all the user's mail.
  • Use procmail, or another program to redirect the message when it is delivered to the user's mailbox.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.