大网数据广告活动
服务器运维问答

How to set MAILTO in cron using Puppet?

· 52CE 我爱测

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 reso…

问题原文

原帖链接 · 030 · CC BY-SA 3.0

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.:

environment

(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.

已采纳解答

原帖链接 · daff · CC BY-SA 4.0

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',
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-05-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。