带有附件错误的 Bash Mutt 电子邮件无法统计:没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42163440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash Mutt email with attachment error Can't stat : No such file or directory
提问by Rob
So i,ve read some other posts and tried out the answers, but i still keep running into this problem so i wanted to post a question here and see if anyone else had any other ideas. Keeping in mind i am pretty new to bash so i am iffy on whats available currently for what i,m looking for.
所以我已经阅读了一些其他帖子并尝试了答案,但我仍然遇到这个问题,所以我想在这里发布一个问题,看看其他人是否有任何其他想法。请记住,我对 bash 还很陌生,所以我不确定目前我正在寻找什么可用的东西。
I am trying to automate a process that creates a file then sends it to me. All the above is fine, until i try to automatically email myself the file.
我正在尝试自动化一个创建文件然后将其发送给我的过程。以上一切都很好,直到我尝试自动将文件通过电子邮件发送给自己。
I have this line of code for it
我有这行代码
echo "report" | mutt -- "$USEREMAIL" -s "report" -a "my_scripts/cid_reports/trb345432.csv"
When it tries to run this command it throws an error like
当它尝试运行此命令时,它会引发类似错误
Can't stat my_scripts/cid_reports/trb345432.csv: No such file or directory
my_scripts/cid_reports/trb345432.csv: unable to attach file.
Can't stat my_scripts/cid_reports/trb345432.csv: No such file or directory
my_scripts/cid_reports/trb345432.csv: unable to attach file.
Any ideas on how i can fix this? I thought mutt was good to handle this, I am going to play with the mail feature and see if i can get any success with that.
关于如何解决这个问题的任何想法?我认为 mutt 可以很好地处理这个问题,我将使用邮件功能,看看我是否能成功。
The system looks to be running
系统看起来正在运行
Mutt 1.4.2.2i (2006-07-14)
Copyright (C) 1996-2002 Michael R. Elkins and others.
Mutt comes with ABSOLUTELY NO WARRANTY; for details type `mutt -v
回答by Ljm Dullaart
The no such file or directory
in general means that the file cannot be found. Because you're using a relative path, it might be that you are in a different directory?
在no such file or directory
一般意味着该文件无法找到。因为您使用的是相对路径,所以您可能在不同的目录中?
If you type cat my_scripts/cid_reports/trb345432.csv
from the same directory as you run the script, is the file there?
如果您cat my_scripts/cid_reports/trb345432.csv
在运行脚本的同一目录中键入,文件是否在那里?
Or otherwise. if you use an absolute path (usually '/home/'uid'/my_scripts/cid_reports/trb345432.csv` but your path may be duifferent), does the script find the file?
否则。如果您使用绝对路径(通常是 '/home/'uid'/my_scripts/cid_reports/trb345432.csv` 但您的路径可能不同),脚本会找到该文件吗?
(or should this have been a comment in stead of an answer, eventhough it tries to guide through finding the error?)
(或者这应该是评论而不是答案,即使它试图引导查找错误?)
回答by haitaoli
mutt -h
-a <file> [...] -- attach file(s) to the message
The list of files must be terminated with the "--" sequence, so,
文件列表必须以“--”序列结束,因此,
echo "hello world" | mutt -s "title" -a /home/test.txt -- ***@**.com
You need to add "--".
您需要添加“--”。
回答by Gordon Davisson
From your comments to Ljm Dullaart's answer, you're actually storing the file path in a variable, then using it something like this:
从您的评论到 Ljm Dullaart 的回答,您实际上是将文件路径存储在一个变量中,然后像这样使用它:
FILE="~/my_scripts/cid_reports/file.csv"
echo "report" | mutt -- "$USEREMAIL" -s "report" -a "$FILE"
If that's what you're doing, the problem is that ~
is in double-quotes, and therefore doesn't get expanded to the actual path to your home directory. Thus, it's looking for a sub directory literally named "~" under the current working directory, and not finding it. In order for ~
to be expanded to the path to your home directory, leave it and the following /
unquoted, like this:
如果这就是你正在做的,问题是~
双引号,因此不会扩展到你的主目录的实际路径。因此,它在当前工作目录下寻找一个字面名为“~”的子目录,但没有找到它。为了~
扩展到您的主目录的路径,请保留它和以下不带/
引号的内容,如下所示:
file=~/"my_scripts/cid_reports/file.csv"
echo "report" | mutt -- "$useremail" -s "report" -a "$file"
Note that I've also switched the variable names to lowercase. This is a best practice to avoid conflicts with the various environment variables that have special meanings; the special ones are all caps, so if you use lower- or mixed-case, you'll never accidentally trip over them.
请注意,我还将变量名称切换为小写。这是避免与具有特殊含义的各种环境变量发生冲突的最佳实践;特殊的都是大写的,所以如果你使用小写或混合大小写,你永远不会不小心被它们绊倒。
回答by M.S. Arun
SIMPLE ANSWER
简单的答案
export EMAIL="[email protected]" | mutt -e "set content_type=text/html" -s "Test Mail" -c "[email protected]" -a /tmp/attachment.txt -- "[email protected]" < /tmp/message.html
Please use the following syntax while attaching files with 'mutt'.
# mutt -a file -- user@domain
For example;
# mutt -a /tmp/test.txt -- [email protected]
Relevant snippets from the man page of mutt is given below.
Raw -a file [...] Attach a file to your message using MIME. When attaching single or multiple files, separating filenames and recipient addresses with "--" is mandatory,
e.g. mutt -a image.jpg -- addr1 or mutt -a img.jpg *.png -- addr1 addr2. The -a option must be placed at the end of command line options.
使用“mutt”附加文件时,请使用以下语法。
# mutt -a file -- user@domain
例如;
# mutt -a /tmp/test.txt -- [email protected]
下面给出了来自 mutt 手册页的相关片段。
Raw -a file [...] 使用 MIME 将文件附加到您的邮件中。附加单个或多个文件时,必须使用“--”分隔文件名和收件人地址,
例如 mutt -a image.jpg -- addr1 或 mutt -a img.jpg *.png -- addr1 addr2。-a 选项必须放在命令行选项的末尾。