The script is working when executed from terminal but, it's giving "(CRON) info (No MTA installed, discarding output)" information when executed from crontab.
Below are my script contents. I have 2 scripts, and a master scripts which executes these two scripts sequentially. You can create them as it is in your system too for testing. I haven't written anything complex here.
testpad1.sh. Script is written with error intentionally.
#!/bin/bash echo "This is script one. sleep 3
#!/bin/bash echo "This is script two" sleep 3
#!/bin/bash mkdir -p logs ./testpad1.sh &> logs/testpad1.log echo `date` ./testpad2.sh &> logs/testpad2.log echo `date`
As you can see, the script masterpad.sh redirects other two scripts' output to their respective log files.
Here is the cronjob.
* * * * * /opt/scripts/masterpad.sh
It's working without issues when executed from terminal, by creating testpad1.log and testpad2.log along with expected output.
But if I schedule the same in crontab, it's giving "(CRON) info (No MTA installed, discarding output)" error. This error was checked by excecuting,
"grep CRON /var/log/syslog".
Since a user in comment section doubted this post with other post, Below is the output to show that, error was not there previously but have occurred only after I added the cronjob. This is the previous output of "grep CRON /var/log/syslog" command.
CMD (/opt/scripts/masterpad.sh &> /opt/scripts/logs/masterpad.log) CMD (/opt/scripts/masterpad.sh) CRON: (CRON) info (No MTA installed, discarding output) CRON: (padmahasa) CMD (/opt/scripts/masterpad.sh) CRON: (CRON) info (No MTA installed, discarding output)
Update 2: Summarized answer from comments and accepted answer.
To get both STDOUT and STDERR from other scripts that are invoked from master script or command (which crontab executes), can use both "&>" or still better option "|& tee" redirection or you can use any other suitable option as in this table but, to capture STDOUT and STDERR of master script or command, "/absolute/path/to/script > absolute/path/to/logfile 2>&1" is the only format that works. Hence the modifications to
#!/bin/bash mkdir -p logs ./testpad1.sh |& tee logs/testpad1.log echo `date` ./testpad2.sh |& tee logs/testpad2.log echo `date`
2. crontab job
* * * * * /opt/scripts/masterpad.sh > /opt/scripts/logs/masterpad.log 2>&1
Thank you all for supporting.