Katello 4.1 foreman crontab

It seems with katello 4.1 /etc/cron.d/foreman has been modified to include a timestamp, 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

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

before.

The problem is that a pipeline separates commands where each has its own file descriptors, thus the redirect at the end only applies to the gawk command. This means, if the rake command has some output to standard error it doesn’t get redirected into cron.log anymore but instead causes a cron email. Only the rake output to standard output is piped into standard input of gawk…

It seems to be introduced in Foreman 2.5 by this commit Fixes #27239: Add timestamps to cron actions in Foreman · theforeman/foreman-packaging@54edda2 · GitHub

cc @ehelms and @evgeni who worked on this.

Even worse: the percent sign “%” has special meaning in a crontab. 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.

In other words: the % is converted to a newline causing the cronjobs to fail with:

/bin/sh: -c: line 0: unexpected EOF while looking for matching `''
/bin/sh: -c: line 1: syntax error: unexpected end of file

So basically all cronjobs in /etc/cron.d/foreman are broken…

@gvde would you mind filing an issue for it for packaging? We’re working on Foreman 2.5.1 right now (Foreman 2.5.1 release process) and we should include a fix for it.

1 Like

Created issue Bug #32859: foreman 2.5 /etc/cron.d/foreman broken - Packaging - Foreman including a fix which is working for me.

1 Like

this has been applied to nightly and 2.5.1, thanks!

2 Likes