Update: cron string is now correct in structure.
I have the mailto:user1@domain.com,user2@domain.com
option configured in my crontab
I have this crontask scheduled right now:
*/5 * * * * root /bin/bash /scripts/db-bkup-test &>/tmp/myDbBack.log;
mailx -s "Nightly Test Database Back-up Is Running Successfully" user@domain.com,user1@domain.com
*/5 * * * * root /bin/bash /scripts/db-bkup-test &>/tmp/myDbBack.log;
mail -s "Nightly Test Database Back-up Is Running Successfully" user@domain.com,user1@domain.com
I get the errors that /bin/bash mail cannot be found in an email. I find this hilarious. So how can I fix this error?
Best Answer
This is how you edit your cron file:
Here is an example of basic cronjob which dumps the database every 6 hours and sends an email, the email will contains whatever the command outputs to standard output to Tom Hanks and Tom Cruise:
Now for mail command to work, you will need a MTA agent. Install postfix to get the mail command through your terminal in ubuntu/debian:
or
replace dnf with yum for older Redhat or Fedora.
For mailx you can install bsd-mailx on ubuntu/debian:
If you already have postfix installed, you can troubleshoot using this command in a terminal on ubuntu/debian:
Open port 25 using iptables:
Since you want root to run the cronjob, use
Then add your cronjob like this:
mail command will need a email body which we are providing null (nothing)