Bug #32859
closedforeman 2.5 /etc/cron.d/foreman broken
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
Updated by Ewoud Kohl van Wijngaarden over 3 years ago
- Target version set to 2.5.1
Updated by The Foreman Bot over 3 years ago
- Status changed from New to Ready For Testing
- Assignee set to Evgeni Golov
- Pull request https://github.com/theforeman/foreman-packaging/pull/6817 added
Updated by The Foreman Bot over 3 years ago
- Pull request https://github.com/theforeman/foreman-packaging/pull/6818 added
Updated by The Foreman Bot over 3 years ago
- Pull request https://github.com/theforeman/foreman-packaging/pull/6820 added
Updated by The Foreman Bot over 3 years ago
- Pull request https://github.com/theforeman/foreman-packaging/pull/6822 added
Updated by Evgeni Golov over 3 years ago
- Status changed from Ready For Testing to Closed
Applied in changeset foreman-packaging|25587bbcb334928db123040b0d1d7d28555c2373.
Updated by Evgeni Golov over 3 years ago
- Assignee deleted (
Evgeni Golov) - Target version deleted (
2.5.1) - Fixed in Releases 2.5.1 added
- Fixed in Releases deleted (
3.0.0)
Updated by The Foreman Bot over 2 years ago
- Pull request https://github.com/theforeman/foreman-packaging/pull/7749 added
Updated by Ewoud Kohl van Wijngaarden over 2 years ago
- Pull request deleted (
https://github.com/theforeman/foreman-packaging/pull/7749)