Operating System - HP-UX
1819682 Members
3804 Online
109605 Solutions
New Discussion юеВ

MAILTO doesn't work with Crontab

 
Allan Umandap
Advisor

MAILTO doesn't work with Crontab

Hi Guys,

I am trying to setup the mailto in my cron. I created a txt file cron_job1.job.Inside it are these entries:

MAILTO=xxxx@domain.com
10 * * * * /home/group/do.sh

but when i tried to add it using this command:

crontab cron_job1.job

i am getting this error:
MAILTO=xxxx@domain.com
crontab: error on previous line; unexpected character found in line.

Pls. help me guys.
6 REPLIES 6
Devesh Pant_1
Esteemed Contributor

Re: MAILTO doesn't work with Crontab

Allan,
is MAILTO a defined variable to a mailx command ?
if not, this will not work.

Why don't you try using mailx instead in your script do.sh

Add the line mailx -s " subject of the email" xxxx@domain.com < outputfile

and that should work

thanks
DP
Allan Umandap
Advisor

Re: MAILTO doesn't work with Crontab

Hi DP,

Are you sayin that i should put MAILTO=xxxx@domain.com inside my script? I thought i just need to put this inside the cron txt i created.

Thanks.
Isralyn Manalac_1
Regular Advisor

Re: MAILTO doesn't work with Crontab

Hi Allan,

MAILTO should be a variable defined within the script. This is how I'd put it in a script:

MAILTO=xxx@domain.com
mailx -s "Test Mail" $MAILTO

Regards,

ira
Allan Umandap
Advisor

Re: MAILTO doesn't work with Crontab

Hi Guys,

I thought by default cron will send the results to root or anyone running the cron...how can i instead of sending it to /var/mail/xxxx forward the mail to my xxxx@domain.com

thnx...
Victor Fridyev
Honored Contributor

Re: MAILTO doesn't work with Crontab

Hi,

The crontab line must look as follows:
10 * * * * export MAILTO=xxxx@domain.com; /home/group/do.sh


HTH
Entities are not to be multiplied beyond necessity - RTFM
C. Beerse_1
Regular Advisor

Re: MAILTO doesn't work with Crontab

I think you refer to the MAILTO option in linux's crontab. I'm sorry to say that is a fairly new crontab option, I've only seen in crontab available on some linux distributions.

For those to know: it sends the output of the crontab entries to the specified mailbox, not to the mailbox of the crontabs user.

On HP-UX you should either do it in your crontab-script (as proposed by the others) or at the receiving end, create an alias for root in /etc/aliases or some forwarding from ~/.forward or using procmail to selectively handle root-s mail.
make everything as simple as possible, not simpler (A.Einstein??)