Mutt failing as cron job with 'Couldn't lock /sent'

我的梦境 提交于 2020-01-25 08:53:07

问题


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.

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

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.)

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

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

email_file script:-

#!/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

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.


回答1:


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

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.

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'

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 $


来源:https://stackoverflow.com/questions/59037545/mutt-failing-as-cron-job-with-couldnt-lock-sent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!