Como definir o MAILTO no cron usando o Puppet?

2

A expectativa era de que haveria um atributo mailto , mas a esta fonte nega que

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

Os documentos não indicam se mailto é suportado, por exemplo:

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.

    
por 030 25.05.2016 / 01:27

3 respostas

2

O tipo Puppet incorporado cron , conforme mencionado na pergunta uma propriedade chamada environment que pode ser usada para definir variáveis de ambiente para o cronjob gerenciado.

Nesse caso, seria assim, definindo a variável MAILTO como foobar , para que a saída do cronjob seja enviada para o usuário foobar :

cron { 'some-cron-job':
  ...
  environment => 'MAILTO=foobar',
}
    
por 26.05.2016 / 17:30
5

Você pode usar um módulo do fantoche forge para gerenciar cron e adicionar variáveis de ambiente ao cron job. Eu usei este , pode haver outros .

Você pode fazer isso

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

Entre outras coisas, define as variáveis de ambiente MAILTO e PATH.

    
por 25.05.2016 / 07:57
0

cron envia a saída ao usuário que está executando o trabalho. Se você quiser redirecionar o e-mail, há algumas opções.

  • Manipule a saída e a correspondência no script que está executando o trabalho.
  • Use uma entrada no arquivo de aliases de e-mail para redirecionar a saída. Isso redirecionará todos os e-mails do usuário.
  • Use procmail ou outro programa para redirecionar a mensagem quando ela for entregue na caixa de correio do usuário.
por 25.05.2016 / 03:31