Manual operation execution, crontab timing task execution error, brother K

Source: Internet
Author: User

Recently sent an automatic inspection of a machine to send e-mails


All the other machines used to be sendmail.

It's no problem to execute the following command directly


This one is postfix because of the other business.


Here are my scheduled tasks.

0 8 * * */opt/xunjian/xunjian.sh >/opt/xunjian/xunjian;mail-s ' 22.44.55.66 ' [email protected] </opt/xunjian/xunj Ian

Ideal for manual execution, direct display of results in messages


/opt/xunjian/xunjian.sh >/opt/xunjian/xunjian

The previous command has no problem and can be viewed through the results.

I'm brother K.


Mail-s ' 22.44.55.66 ' [email protected] </opt/xunjian/xunjian

The subsequent commands are no problem with manual operation alone.


If you add this order to crontab,

Then the result you see in the message is an attachment with the following name

Tcmime.1205.1205.16703.bin


So the question is, why is it so?

Let's think about it, if there is a problem with the mail configuration, the message will never receive

Messages can be received but displayed as attachments


See Baidu Google, a lot of the same problem

Finally found a reliable answer: crontab environment variables


How to fix it, it's easy to add a reference global variable

Source/etc/profile

I'm brother K.

I'm going to change the order to show the mail as normal.

0 8 * * */opt/xunjian/xunjian.sh >/opt/xunjian/xunjian;source/etc/profile;mail-s ' 133.22.123.22 ' [email protected] </opt/xunjian/xunjian

Or you can execute the file.

0 8 * * */opt/mail.sh


vi/opt/mail.sh

#!/bin/bash

Source/etc/profile

/opt/xunjian/xunjian.sh >/opt/xunjian/xunjian

Mail-s ' 133.22.123.22 ' [email protected] </opt/xunjian/xunjian


Hope can help everyone, thank you

Manual operation execution, crontab timing task execution error, brother K

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.