0

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?

2

This is how you edit your cron file:

crontab -e

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:

MAILTO="tom@hanks.com,tom@cruise.com"
0 */6 * * * mysqldump -u tom_hanks -pHANKS_TOM --host=10.0.0.1 mycompany > /home/tom_hanks/db.sql

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:

sudo apt-get update && sudo apt-get install -y postfix mailutils

or

sudo dnf update && sudo dnf install postfix mailx -y 

replace dnf with yum for older Redhat or Fedora.

For mailx you can install bsd-mailx on ubuntu/debian:

sudo apt-get update && sudo apt-get install bsd-mailx 

If you already have postfix installed, you can troubleshoot using this command in a terminal on ubuntu/debian:

sudo dpkg-reconfigure postfix

Open port 25 using iptables:

iptables -I INPUT -p tcp -m tcp --dport 25 -j ACCEPT

Since you want root to run the cronjob, use

sudo crontab -e

Then add your cronjob like this:

*/5 * * * * sh /scripts/db-bkup-test.sh &> /tmp/myDbBack.log &&  mail -s "Nightly Test Database Back-up Is Running Successfully" user@domain.com,user1@domain.com < /dev/null

mail command will need a email body which we are providing null (nothing)

| improve this answer | |
0

So not really familiar with linux server side, figured it out. I installed mailx.

yum install mailx

Using this source.

I tested the service using cmd:

$ mailx -s 'Test' user@domain.com > /dev/null

Updated the cron to reflect the empty body same as above > /dev/null

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.