【问题标题】:Mutt failing as cron job with 'Couldn't lock /sent'Mutt 以“无法锁定/发送”作为 cron 作业失败
【发布时间】:2019-11-25 17:53:08
【问题描述】:

我有一个 bash 脚本,它从 /tmp 中提取文件并将它们通过电子邮件发送给我。我以 root 身份运行此脚本,它运行良好,但我正在尝试使用 crontab 自动执行此操作。

将作业添加到 crontab,再次以 root 身份运行,现在我得到“无法锁定 /sent”。

我设法通过在 Muttrc 中更改文件的名称来确认它正在使用 /root 中的文件,并尝试了 600 和 777 的权限。

(也得到一个错误的分段错误,希望如果我修复上述问题会消失。)

任何人都知道为什么 Mutt 与具有相同用户和相同文件的 cron 作业不同。

我将脚本简化如下,并且完全相同,在 root shell 中工作,但不在 crontab 中。 错误:-

Couldn't lock /sent
/data/mediators/email_file: line 5:  1666 Segmentation fault      mutt $email -s "test" -i /tmp/test.txt < /dev/null

email_file 脚本:-

#!/bin/bash
email=——@——.com
mutt $email -s "test" -i /tmp/test.txt < /dev/null

crontab:-

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=——@—-.com
HOME=/

54 02 * * * root /data/mediators/email_file

我还在作业中添加了 printenv,并与运行正常的服务器进行了比较。不同之处在于工作系统有 USER=root,而非工作系统没有显示此变量已设置。

【问题讨论】:

  • 没有脚本我们无能为力

标签: cron root mutt


【解决方案1】:

问题是 crontab 中的 HOME=/ env 变量和默认为 ~/sent 的默认 mutt record 配置的组合。

mutt 将发送的电子邮件存储在记录文件中。所以选择是否要保留它们(修复 crontab 的 env var HOME 或将 mutt 的 record 设置为有意义的值。

将此选项添加到 email_file 中的 mutt 命令中如果要设置:

-e 'set record=/root/sent'

或取消设置:

-e 'unset record'

您可以在手册页中找到更多信息 muttrc(5)

record

Type: path
Default: “~/sent”

This specifies the file into which your outgoing messages should be appended. (This is meant as the primary method for saving a copy of your messages, but another way to do this is using the “my_hdr” command to create a “Bcc:” field with your email address in it.)

The value of $record is overridden by the $force_name and $save_name variables, and the “fcc-hook” command. Also see $copy and $

【讨论】:

    猜你喜欢
    • 2019-06-04
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 2013-11-03
    • 2016-10-15
    • 2021-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多