-
Environments like Ubuntu use
/bin/sh
for executing crontab scripts rather than/bin/bash
used byCentOS
. To avoid failure with your crontab scripts, you can addSHELL=/bin/bash
to the beginning of your crontab file to change the shell accordingly. Commands like
source
fail when/bin/sh
shell is used.Many distributions use
/bin/bash
as the shell and it supports commands likesource
. On Ubuntu, however,/bin/dash
is used which does not supportsource
. Most shells use.
instead ofsource
. If you cannot edit your script, try to change the shell that runs it. -
The working directory varies in different environments. To ensure your cron task is executed in the correct working directory, you should include the command to change to the desired directory before executing your script or dependent scripts. ALternatively, you can include it in your crontab command, e.g.
58 23 * * * cd /home/xxxx/desired-dir/scripts && ./my_script.sh
-
How to fix No MTA installed errors in /var.log/syslog: By default, the output of each cron job is collected by cron and sent via email when the job is complete. If there is no output, no mail is sent.
If you see
(CRON) info (No MTA installed, discarding output)
errors in your syslog it means that there is output from your cron job but your server does not have a Message Transfer Agent installed to process the output into an email.This is not a problem with your cron job itself but with the system.
To fix this error,
-
Install an MTA like the popular
postfix
. This can be installed in most cases from a package manager. For example, on Ubuntu you may run:sudo apt-get install postfix
If you select local installation, the output from your cron jobs will be relayed to a local "mailbox" that you can easily tail:
sudo tail -f /var/mail/<cron user>
Another option, if you don't care about cron emails, is to silence the error by disabling emails from your crontab. The easiest way to do this for all cron jobs is to add this to the top of the crontab file:
MAILTO=""
-
Created
June 10, 2022 17:59
-
-
Save barbietunnie/6ce31a665a81ea57ea64687a446ba85e to your computer and use it in GitHub Desktop.
Crontab Notes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment