本文介绍了mutt无法执行cron作业,并显示“无法锁定/发送"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个bash脚本,该脚本从/tmp中拾取文件并将其通过电子邮件发送给我.我以root身份运行此脚本,并且运行良好,但是我正尝试使用crontab使其自动化.

I have a bash script which picks up files from /tmp and emails them to me. I run this script as root and it works perfectly but I am trying to get this automated with crontab.

将作业添加到crontab中,再次以root身份运行,现在我得到无法锁定/发送".

Added the job to crontab, again running as root, and now I get 'Couldn't lock /sent'.

我设法通过更改Muttrc中的名称来确认它正在使用/root中的文件,并尝试在600和777上获得许可.

I managed to confirm it's using the file in /root by changing it's name in Muttrc and tried permission at 600 and 777.

(还会出现错误细分错误,希望如果我解决以上问题,该错误会消失.)

(Also getting an error Segmentation fault, hoping that will go away if I fix the above.)

任何人都知道为什么Mutt在具有相同用户和相同文件的cron作业中会有所不同.

Anyone any ideas why Mutt is different as a cron job with the same user and the same file.

我对脚本进行了如下简化,并且操作完全相同,可以在root shell中运行,但不能在crontab中运行.错误:-

I simplified the script as follows and is doing exactly the same, works from root shell, but not in crontab.error:-

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

电子邮件文件脚本:-

#!/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添加到作业中,并与运行OK的服务器进行了比较.区别在于,工作系统具有USER = root,而不工作的系统则未显示该变量已设置.

I also added printenv to the job and compared to a server where this runs OK. The difference is that the working system has USER=root, whereas the non-working one does not show this variable as being set.

推荐答案

问题是crontab中的HOME=/ env变量和默认为〜/sented的默认mutt record 配置的组合.

The issue is combination of HOME=/ env variable in crontab and default mutt record configuration which defaults to ~/sent.

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

mutt stores sent emails in the record file. So choose whether you want to keep them (fix crontab's env var HOME or set mutt's record to meaningful value.

将此选项添加到电子邮件文件中的mutt命令中:如果要设置它:

Add this option to mutt command in email_file If you want to set it:

-e 'set record=/root/sent'

或通过以下方式取消设置:

or unset it with:

-e 'unset record'

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

You can find more in man pages 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 $

这篇关于mutt无法执行cron作业,并显示“无法锁定/发送"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 02:06