LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Cron Job not sending E-mails (https://www.linuxquestions.org/questions/linux-newbie-8/cron-job-not-sending-e-mails-4175463709/)

FortressMvelez 05-28-2013 01:14 AM

Cron Job not sending E-mails
 
Hello,

I have been trying to set up a cron job that sends me an e-mail with a subject line so I know the cron job did run.

I was looking the information from the following:

http://www.linuxquestions.org/questi...n-jobs-886164/

I did what the post said but I never got the e-mail and I checked the spam folder and nothing.

Here is the way I set up the cron job in crontab -e:

MAILTO=emailaddress@gmail.com?subject=Maldet Updated!!
* 1 * * 0 /usr/local/sbin/maldet -u

I set it up for different times to see if it was running and to keep an eye on my e-mail but I never get anything and I'm not sure if I am missing something which is why it is not running or where else to check to see if it ran or not because I never get the e-mail.

Thanks for the help in advance!

chrism01 05-28-2013 02:20 AM

MAILTO can ONLY be an address.
Used by cron to report an error if a cronjob fails.
The default is usually the job owner (or root).

If you want to send an email, ignore that and use an example from here http://stackoverflow.com/questions/2...-mailx-command

cron howto http://www.adminschoice.com/crontab-quick-reference

You probably don't want to send an email every minute ...

Note also that places like google, yahoo etc often won't accept emails from dynamic IPs because of the amt of SPAM that comes from such systems.
If you want to pass an email out, you may have to go via your ISP's mailservers, to get around that problem.

FortressMvelez 05-28-2013 08:22 AM

Hello,

Thank you for your reply! The information you have provided was very helpful in understanding how this works! So, from what I read you can use mailx to send out the e-mail as I wanted by using the following command:

echo "something" | mailx -s "subject" recipient@somewhere.com

Would this go before the cron job or next to it? For example:

echo "something" | mailx -s "subject" recipient@somewhere.com
* 1 * * 0 /usr/local/sbin/maldet -u

OR

* 1 * * 0 /usr/local/sbin/maldet -u | echo "something" | mailx -s "subject" recipient@somewhere.com

OR

* 1 * * 0 /usr/local/sbin/maldet -u > echo "something" | mailx -s "subject" recipient@somewhere.com

I think if I can get this one part clear everything would work out perfectly with the information you have provided me!

Thanks!!! :)

chrism01 05-29-2013 12:23 AM

Depends what maldet does, but you could try
Code:

* 1 * * 0 (/usr/local/sbin/maldet -u )| mailx -s "subject" recipient@somewhere.com
You should test your ideas from the cli first (ie not within cron) to see if they work, then add to cron.

FortressMvelez 06-02-2013 08:42 PM

Thanks!!!
 
Hey, did what you told me in your previous reply and it worked perfect! Thank you so much for your help!!!!

Quote:

Originally Posted by chrism01 (Post 4961070)
Depends what maldet does, but you could try
Code:

* 1 * * 0 (/usr/local/sbin/maldet -u )| mailx -s "subject" recipient@somewhere.com
You should test your ides from the cli first (ie not within cron) to see if they work, then add to cron.


chrism01 06-02-2013 09:26 PM

Glad to help :)


All times are GMT -5. The time now is 07:22 PM.