如何在cron中使用Puppet设置MAILTO?

期望是会有一个mailto属性,但是这个来源否认

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

该文档不指示是否支持mailto,例如:

环境

(属性:该属性表示目标系统上的具体状态。)

任何与此cron作业相关的环境设置。 它们将被存储在头文件和crontab中的作业之间。 不能保证其他早期的设置不会影响给定的cron作业。

此外,Puppet不能自动确定现有的非托pipe环境设置是否与给定的cron作业相关联。 如果你已经有环境设置的cron作业,那么Puppet会将这些设置保留在文件中的相同位置,但不会将它们与特定作业相关联。

设置应该像在crontab中显示的一样被指定,例如,PATH = / bin:/ usr / bin:/ usr / sbin。

问题中引用的内置Puppettypescron具有一个名为environment的属性,可用于设置托pipe的cronjob的环境variables。

在这种情况下,它看起来像这样,将MAILTOvariables设置为foobar以便cronjob的输出将被邮寄给用户foobar

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

您可以使用伪造的模块来pipe理cron并将环境variables添加到cron作业中。 我用过这个 ,可能还有其他的 。

你可以这样做

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

其中包括MAILTO和PATH环境variables。

cron将输出发送给运行作业的用户。 如果你想redirect的邮件有几个选项。

  • 处理输出并邮寄运行作业的脚本。
  • 使用电子邮件别名文件中的条目来redirect输出。 这将redirect所有用户的邮件。
  • 使用procmail或其他程序将消息发送到用户的邮箱时redirect。