Project

General

Profile

Bug #32859

foreman 2.5 /etc/cron.d/foreman broken

Added by Gerald Vogt 5 months ago. Updated 5 months ago.


Description

See also here: here

The foreman crontab in /etc/cron.d/foreman changed to include a timestamp to the output, e.g.

*/30 * * * *    foreman    /usr/sbin/foreman-rake ldap:refresh_usergroups | gawk '{ print strftime("[%Y-%m-%d %H:%M:%S]"), $0 }' >>/var/log/foreman/cron.log 2>&1

instead of
*/30 * * * *    foreman    /usr/sbin/foreman-rake ldap:refresh_usergroups >>/var/log/foreman/cron.log 2>&1

However, there are two problems here:

1. The percent sign % has special meaning in a crontab file and is replaced with a newline and the remainder is sent as standard input.

From crontab(5):

The "sixth" field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a newline or a "%" character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the cronfile. A "%" character in the command, unless escaped with a backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.

2. The redirection only applies to the second command not the pipe as a whole. This means that standard error output of the rake command now is sent to standard error and it not redirected. It ends up in a cron mail instead of cron.log.

Correct would be:

*/30 * * * *    foreman    /usr/sbin/foreman-rake ldap:refresh_usergroups 2>&1 | gawk '{ print strftime("[\%Y-\%m-\%d \%H:\%M:\%S]"), $0 }' >>/var/log/foreman/cron.log 2>&1

or
*/30 * * * *    foreman    /usr/sbin/foreman-rake ldap:refresh_usergroups |& gawk '{ print strftime("[\%Y-\%m-\%d \%H:\%M:\%S]"), $0 }' >>/var/log/foreman/cron.log 2>&1

Associated revisions

Revision 25587bbc (diff)
Added by Evgeni Golov 5 months ago

fixes #32859 - fix crontab format

Revision 0b11462b (diff)
Added by Evgeni Golov 5 months ago

Fixes #32859 - fix cron syntax

History

#1 Updated by Ewoud Kohl van Wijngaarden 5 months ago

  • Target version set to 2.5.1

#2 Updated by The Foreman Bot 5 months ago

  • Assignee set to Evgeni Golov
  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman-packaging/pull/6817 added

#3 Updated by The Foreman Bot 5 months ago

  • Pull request https://github.com/theforeman/foreman-packaging/pull/6818 added

#4 Updated by The Foreman Bot 5 months ago

  • Fixed in Releases 3.0.0 added

#5 Updated by The Foreman Bot 5 months ago

  • Pull request https://github.com/theforeman/foreman-packaging/pull/6820 added

#6 Updated by The Foreman Bot 5 months ago

  • Pull request https://github.com/theforeman/foreman-packaging/pull/6822 added

#7 Updated by Evgeni Golov 5 months ago

  • Status changed from Ready For Testing to Closed

#8 Updated by Evgeni Golov 5 months ago

  • Target version deleted (2.5.1)
  • Assignee deleted (Evgeni Golov)
  • Fixed in Releases 2.5.1 added
  • Fixed in Releases deleted (3.0.0)

Also available in: Atom PDF