Ale*_*Kim 8 email linux ubuntu php cron
我在 cronjob 中有以下命令:
*/5 * * * * php /var/www/domain/yii rss/parse
Run Code Online (Sandbox Code Playgroud)
它以错误的字符集输出电子邮件:
Content-Type: text/plain; charset=ANSI_X3.4-1968
Run Code Online (Sandbox Code Playgroud)
但是当我直接在 CLI 中启动该命令并将其输出到日志时:
php /var/www/domain/yii rss/parse > log
Run Code Online (Sandbox Code Playgroud)
我得到了正确的编码 - UTF-8
已经尝试在 /etc/environment 中设置 lang:
LANG=en_US.UTF-8
Run Code Online (Sandbox Code Playgroud)
重新启动了 cron,但它仍然通过 CRON 使用 ANSI。有任何想法吗?
Ale*_*Kim 13
通过添加到 crontab 解决了我的问题:
crontab -e
Run Code Online (Sandbox Code Playgroud)
在文件的顶部我写道:
CONTENT_TYPE="text/plain; charset=utf-8"
Run Code Online (Sandbox Code Playgroud)
现在我所有的 cron 工作电子邮件都是 UTF-8 字符集。
我认为,当您通过 CLI 发出命令时,您会得到 utf-8 聊天集,因为您使用的是 MAC OS PC 或 Linux PC
\n\n我之所以这么说是因为你的 PC 的当前 LANG 开始复制到你的 ssh 会话中
\n\ngrep -i LANG /etc/ssh/sshd_config \nAcceptEnv LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES\nRun Code Online (Sandbox Code Playgroud)\n\n来自 man sshd_config
\n\nAcceptEnv\n Specifies what environment variables sent by the client will be copied into the session\xe2\x80\x99s environ(7). See SendEnv in ssh_config(5) for how to\n configure the client. Note that environment passing is only supported for protocol 2. Variables are specified by name, which may contain the\n wildcard characters \xe2\x80\x98*\xe2\x80\x99 and \xe2\x80\x98?\xe2\x80\x99. Multiple environment variables may be separated by whitespace or spread across multiple AcceptEnv directives.\n Be warned that some environment variables could be used to bypass restricted user environments. For this reason, care should be taken in the\n use of this directive. The default is not to accept any environment variables.\nRun Code Online (Sandbox Code Playgroud)\n\n你的 crond 进程正在使用 charset=ANSI_X3.4-1968,也许这是默认的系统 LANG,但如果想更改它
\n\n man 5 crontab\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
4603 次 |
| 最近记录: |