Bug 264976

Summary: crontab task fail to work if stdout redirected
Product: Base System Reporter: Dmitry Cheshkov <dcheshkov>
Component: confAssignee: freebsd-bugs (Nobody) <bugs>
Status: New ---    
Severity: Affects Only Me CC: admin, chris
Priority: ---    
Version: 13.1-STABLE   
Hardware: amd64   
OS: Any   

Description Dmitry Cheshkov 2022-07-01 12:24:01 UTC
The following periodic task fail to work if stdout/stderr redirection appended.
*/5 * * * * /bin/date | /usr/local/bin/test2 > & /dev/null
- not work, but
*/5 * * * * /bin/date | /usr/local/bin/test2
works well.

And 
/bin/date | /usr/local/bin/test2 > /dev/null 2>&1
resulted in 'Ambiguous output redirect'.

/usr/local/bin/test2 - just short perl script:
#!/usr/local/bin/perl
open(OUT, ">>/var/log/test.log");
print OUT <STDIN>;
close(OUT);
exit(0);

So, how make periodic tasks like this to work? This issue arose after migration from 12.3-STABE to 13.1-STABLE.

Whith best regards,
Dmitry Cheshkov
Comment 1 Vladyslav V. Prodan 2022-07-01 15:40:47 UTC
The following works in cron:
```
0 0 * * *  command > /dev/null 2>&1
0 0 * * *  ( command1 | command2 ) > /dev/null 2>&1
```
Comment 2 Dmitry Cheshkov 2022-07-01 21:58:51 UTC
Actually, problem arose with mrtg script.
in 12.3-stable the following line in the root crontab worked fine

*/5 * * * * /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg > /dev/null 2>&1

but in 13.1-stable does not. Removing of '> /dev/null 2>&1' makes mrtg working. Also, I found, that addition of 'env LANG=C' before '/usr/local/bin/mrtg' makes mrtg working with stdout+stderr redirection to /dev/null in 13.1-stable:

*/5 * * * * env LANG=C /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg > /dev/null 2>&1