Cron作业-通过电子邮件发送的导出文件为空

时间:2018-08-05 21:34:19

标签: shell cron-task

我正在接收来自以下CRON作业的电子邮件,但带有空白文件。我已经检查了/ home / XXXXXX / public_html / tmp /目录,并在该/ tmp /文件夹中创建了一个很好的tqhsa_hikashop_order.txt文件,但是我收到的电子邮件附件为空。

mysql --database=XXXXXXXX_jml_6UCHadruwR8veju3 -u XXXXXXXX_8eh6Nu --password=fRa6r7wRerEtuzud -B -e "SELECT order_number, order_created, order_invoice_number, order_full_price, order_discount_code, order_discount_price, order_payment_method, order_payment_price FROM tqhsa_hikashop_order;" > /home/XXXXXXXX/public_html/tmp/tqhsa_hikashop_order.txt | mail -s "Daily Discount Table Dump" -a /home/XXXXXXXX/public_html/tmp/tqhsa_hikashop_order.txt luke@example.com

有什么想法为什么不附加好文本文件?

1 个答案:

答案 0 :(得分:1)

您需要确保在执行第二个命令之前先完成第一个命令,以使该文件位于磁盘上。

因此从本质上将|替换为&&

mysql \
  --database=XXXXXXXX_jml_6UCHadruwR8veju3 \
  -u XXXXXXXX_8eh6Nu \
  --password=fRa6r7wRerEtuzud \
  -B \
  -e "SELECT order_number, order_created, order_invoice_number, order_full_price, order_discount_code, order_discount_price, order_payment_method, order_payment_price FROM tqhsa_hikashop_order;" > /home/XXXXXXXX/public_html/tmp/tqhsa_hikashop_order.txt \
&& \
mail \
  -s "Daily Discount Table Dump" \
  -a /home/XXXXXXXX/public_html/tmp/tqhsa_hikashop_order.txt luke@example.com

使用示例进行说明:

myuser@myshell:~ $ echo "testing" > testy.txt | cat testy.txt
cat: testy.txt: No such file or directory

myuser@myshell:~ $ echo "testing" > testy.txt && cat testy.txt 
testing
相关问题