Can anyone tell me what the issue with this script?
谁能告诉我这个脚本有什么问题?
(printf "To:myemail@mydomain.com\nSubject: Mail queue cleanup for for My-VPS-Linux\n\n" ; /usr/sbin/exim -bp | awk '/^ *[0-9]+[mhd]/{print "/usr/sbin/exim -Mrm " $3}' ) | bash | /usr/sbin/sendmail myemail@mydomain.com
as soon as I run this via SSH I get this error
一旦我通过SSH运行这个我得到这个错误
bash: line 1: To:myemail@mydomain.com: command not found
bash: line 2: Subject:: command not found
All I want to acheive is to clear the exim queue through this script after defining in cronjob. When I run following script
我想要实现的是在cronjob中定义后通过此脚本清除exim队列。当我运行以下脚本时
/usr/sbin/exim -bp | awk '/^ *[0-9]+[mhd]/{print "/usr/sbin/exim -Mrm " $3}' ) | bash | /usr/sbin/sendmail myemail@mydomain.com
it works pretty fine and send me an email after clearing email queue but it does not post any subject or to email address...
它工作得很好,并在清除电子邮件队列后向我发送电子邮件,但它不发布任何主题或电子邮件地址...
Regards, Faraz H. Khan
此致,Faraz H. Khan
2 个解决方案
#1
1
Because you have put the subshell first, your Subject: and To: print lines are printed before the output of exim
, and are being processed by bash
. You should move the subshell later on:
因为您已将子shell放在第一位,所以在exim的输出之前打印了Subject:和To:打印行,并且正在由bash处理。您应该稍后移动子shell:
/usr/sbin/exim -bp | awk '/^ *[0-9]+[mhd]/{print "/usr/sbin/exim -Mrm " $3}' | (printf "To:myemail@mydomain.com\nSubject: Mail queue cleanup for for My-VPS-Linux\n\n"; bash) | /usr/sbin/sendmail myemail@mydomain.com
This prints your Subject: and To: lines before any other output, but bash
will not process those lines.
这会在任何其他输出之前打印您的Subject:和To:行,但bash不会处理这些行。
#2
0
You are sending the print output to bash. You need to send the print output to sendmail. Your )
is in the wrong place. (Assuming the output from that exim|awk
pipe is the body of the email you get and prepending headers the way you are trying will make sendmail
do the right thing, etc., etc..)
您正在将打印输出发送到bash。您需要将打印输出发送到sendmail。你的)在错误的地方。 (假设exim管道的输出是你得到的电子邮件的正文,并按照你尝试的方式预先添加标题会使sendmail做正确的事情,等等。)
#1
1
Because you have put the subshell first, your Subject: and To: print lines are printed before the output of exim
, and are being processed by bash
. You should move the subshell later on:
因为您已将子shell放在第一位,所以在exim的输出之前打印了Subject:和To:打印行,并且正在由bash处理。您应该稍后移动子shell:
/usr/sbin/exim -bp | awk '/^ *[0-9]+[mhd]/{print "/usr/sbin/exim -Mrm " $3}' | (printf "To:myemail@mydomain.com\nSubject: Mail queue cleanup for for My-VPS-Linux\n\n"; bash) | /usr/sbin/sendmail myemail@mydomain.com
This prints your Subject: and To: lines before any other output, but bash
will not process those lines.
这会在任何其他输出之前打印您的Subject:和To:行,但bash不会处理这些行。
#2
0
You are sending the print output to bash. You need to send the print output to sendmail. Your )
is in the wrong place. (Assuming the output from that exim|awk
pipe is the body of the email you get and prepending headers the way you are trying will make sendmail
do the right thing, etc., etc..)
您正在将打印输出发送到bash。您需要将打印输出发送到sendmail。你的)在错误的地方。 (假设exim管道的输出是你得到的电子邮件的正文,并按照你尝试的方式预先添加标题会使sendmail做正确的事情,等等。)