[英]How can I mail a command output via Sendmail
I want to cron a simple commandline output via the standard linux sendmail function (using Centos).我想通过标准的 linux sendmail 函数(使用 Centos)cron 一个简单的命令行输出。
The command is: ll -rt | grep error
命令是: ll -rt | grep error
ll -rt | grep error
This will give me a list of error log files. ll -rt | grep error
这会给我一个错误日志文件的列表。
I want the solution as simple as possible, can I do something like sendmail user@example.com < ll -rt | grep error
我希望解决方案尽可能简单,我可以做类似sendmail user@example.com < ll -rt | grep error
事情吗? sendmail user@example.com < ll -rt | grep error
. sendmail user@example.com < ll -rt | grep error
。 Or is there a more elegant way?或者有更优雅的方式吗?
Btw, this gives me an error output: bash: ll -rt | grep error: No such file or directory
顺便说一句,这给了我一个错误输出: bash: ll -rt | grep error: No such file or directory
bash: ll -rt | grep error: No such file or directory
Thanks for your insights.感谢您的见解。
Use a pipe:使用管道:
ll -rt | grep error | sendmail user@example.com
<
is for redirection from a file, not a command, so it's trying to read from the file named ll
. <
用于从文件重定向,而不是命令,因此它试图从名为ll
的文件中读取。
You obviously already know about pipelines, since you used it to pipe the output of ls
to grep
.您显然已经了解管道,因为您使用它将ls
的输出通过管道传送到grep
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.