我有一个使用mailx 发送电子邮件的bash 脚本。邮箱配置在 .mailrc 中。我以root身份运行它:
linux:~ # ./lprojekt.sh
Resolving host smtp.gmail.com . . . done.
Connecting to 173.194.70.109 . . . connected.
220 mx.google.com ESMTP n20sm30980415wiw.5
>>> EHLO linux.site
250-mx.google.com at your service, [95.49.133.188]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250 ENHANCEDSTATUSCODES
>>> STARTTLS
220 2.0.0 Ready to start TLS
>>> EHLO linux.site
250-mx.google.com at your service, [95.49.133.188]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH
250 ENHANCEDSTATUSCODES
>>> AUTH LOGIN
334 VXNlcm5hbWU6
>>> bG1mYnlkYjlAZ21haWwuY29t
334 UGFzc3dvcmQ6
>>> cHJvamVrdDEyMz==
235 2.7.0 Accepted
>>> MAIL FROM: <lmfbydb9@gmail.com>
250 2.1.0 OK n20sm30980415wiw.5
>>> RCPT TO: <daniel@gadawski.pl>
250 2.1.5 OK n20sm30980415wiw.5
>>> DATA
354 Go ahead n20sm30980415wiw.5
>>> .
250 2.0.0 OK 1335692819 n20sm30980415wiw.5
>>> QUIT
221 2.0.0 closing connection n20sm30980415wiw.5
如您所见,它运行正确。
但是,当我尝试使用 cron 运行此脚本时出现问题。
这是我的 /etc/crontab 内容:
SHELL=/bin/bash
PATH=/usr/bin:/usr/sbin:/sbin:/bin:/usr/lib/news/bin
MAILTO=root
HOME=/root
#
# check scripts in cron.hourly, cron.daily, cron.weekly, and cron.monthly
#
-*/15 * * * * root test -x /usr/lib/cron/run-crons && /usr/lib/cron/run-crons >/dev/null
* * * * * root /root/lprojekt.sh >> /root/Desktop/log.txt
每分钟(现在只用于调试),root 用户都会收到一封邮件:
Message 40:
From root@linux.site Sun Apr 29 13:50:01 2012
X-Original-To: root
Delivered-To: root@linux.site
From: root@linux.site
To: root@linux.site
Subject: Cron <root@linux> /root/lprojekt.sh >> /root/Desktop/log.txt
X-Cron-Env: <SHELL=/bin/bash>
X-Cron-Env: <PATH=/usr/bin:/usr/sbin:/sbin:/bin:/usr/lib/news/bin>
X-Cron-Env: <MAILTO=root>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
Date: Sun, 29 Apr 2012 13:50:01 +0200 (CEST)
Invalid or incomplete multibyte or wide character
. . . message not sent.
这个问题的原因是什么?如何解决?提前感谢您的帮助。