cron工作发送错误字符集的电子邮件

我有一个cronjob中的以下命令:

*/5 * * * * php /var/www/domain/yii rss/parse 

它以错误的字符集输出电子邮件:

 Content-Type: text/plain; charset=ANSI_X3.4-1968 

但是,当我直接在CLI中启动该命令并将其输出到日志时:

 php /var/www/domain/yii rss/parse > log 

我得到正确的编码 – UTF-8

已经尝试在/ etc / environment中设置lang:

 LANG=en_US.UTF-8 

重新启动cron,但它仍然通过CRON使用ANSI。 有任何想法吗?

通过添加到crontab解决了我的问题:

 crontab -e 

在文件的顶部我写道:

 CONTENT_TYPE="text/plain; charset=utf-8" 

现在我所有的cron作业电子邮件都是UTF-8字符集。

我必须为全体用户解决这个问题,而不是特定的问题。 我已经尝试设置/ etc / environment和/ etc / default / locale,然后重新启动cron。 这没有帮助。 对我来说正确的答案是在暴发户脚本中使用env命令(我正在运行的Ubuntu服务器):

env LC_ALL = en_US.UTF-8

 cat /etc/init/cron.conf # cron - regular background program processing daemon # # cron is a standard UNIX program that runs user-specified programs at # periodic scheduled times description "regular background program processing daemon" start on runlevel [2345] stop on runlevel [!2345] expect fork respawn env LC_ALL=en_US.UTF-8 exec cron 

然后我重新启动了cron,并在utf-8中获得了正确的邮件。

当你通过CLI命令时,你得到了utf-8的聊天logging,我想,因为你使用的是MAC OS PC或Linux PC

我告诉过你,因为你的PC的当前LANG开始被复制到你的ssh会话中

 grep -i LANG /etc/ssh/sshd_config AcceptEnv LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES 

从人sshd_config

 AcceptEnv Specifies what environment variables sent by the client will be copied into the session's environ(7). See SendEnv in ssh_config(5) for how to configure the client. Note that environment passing is only supported for protocol 2. Variables are specified by name, which may contain the wildcard characters '*' and '?'. Multiple environment variables may be separated by whitespace or spread across multiple AcceptEnv directives. Be warned that some environment variables could be used to bypass restricted user environments. For this reason, care should be taken in the use of this directive. The default is not to accept any environment variables. 

您的crond进程正在使用字符集= ANSI_X3.4-1968,也许这是默认的系统LANG,但如果想要更改此

  man 5 crontab