I've been trying to get all cron job outputs to a file (not email). The alias is set in /etc/aliases.
logthecron: "|cronlog.sh"
And in crontab MAILTO=logthecron.
The cronlog.sh file writes to output to some file:
#!/bin/sh
$@ 2>&1 | sed -e "s/\(.*\)/[`date`] \1/" >> /tmp/a
I am using sendmail. Sendmail uses smrsh, a restricted shell utility that provides the ability to specify, through the /etc/smrsh directory, an explicit list of executable programs available to Sendmail. So I symlinked cronlog.sh and sendmail to that directory. Something like...
ln -s /root/cron/cronlog.sh /etc/smrsh/
And still keep getting this error.
May 10 09:33:11 sandbox01 smrsh: uid 8: attempt to use "cronlog.sh"
May 10 09:33:11 sandbox01 sendmail[23870]: x4ADXB5Y023868: to="|cronlog.sh", ctladdr=<logthecron@[hostname]> (8/0), delay=00:00:00, xdelay=00:00:00, mailer=prog, pri=30787, dsn=5.0.0, stat=Service unavailable
May 10 09:33:11 sandbox01 sendmail[23870]: x4ADXB5Y023868: x4ADXB5Y023870: DSN: Service unavailable
Note: I am using CentOS v7, the file is executable, email works without issues, tried the entire directory path in the alias and I do not want to write individual cronjob outputs but write all the output of cron jobs to some file.
Reference:
|cronlog.sh. The value ofMAILTOwill always be taken as an email address./rootis usually only accessible to root, so better to put a copy of the script in/etc/smrsh.