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