Cron Job - 如何将输出文件发送到电子邮件 [英] Cron Job - How to send an output file to an email

查看:19
本文介绍了Cron Job - 如何将输出文件发送到电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 crontab 中有这一行:

I have this line in crontab:

* * * * * /var/www/dir/sh/mysql_dumb.sh | mail -s "mysql_dump" example@mail.com

(每分钟只有一个样本)

(every minute only a sample)

所以,一切正常,但电子邮件是空的.

So, all works fine, but the email is empty.

更新:

mysql_dumb.sh 的输出是一个 *.sql 文件,他们将文件保存在一个目录中.

The output from mysql_dumb.sh is a *.sql file and they save the file in a directory.

我如何从这个输出 -> mysql_dumb.sh 发送一个副本(*.sql 文件)到我的电子邮件?

How can I send a copy (*.sql file) from this output -> mysql_dumb.sh to my email?

mysql_dumb.sh:

mysql_dumb.sh:

#!/bin/bash
PATH=/usr/bin:/bin
SHELL=/bin/bash
/usr/bin/mysqldump -u USER -pPASS DATABASE > /var/www/dir/backup/backup_DB_`date +%d_%m_%Y`.sql

推荐答案

如果脚本报告错误,他们可能会转到 stderr,但您只是在重定向 stdout.您可以通过在命令中添加 2>&1 来重定向 stderr:

If the script is reporting errors, they may be going to stderr, but you're only redirecting stdout. You can redirect stderr by adding 2>&1 to the command:

* * * * * /var/www/dir/sh/mysql_dump.sh 2>&1 | mail -s "mysql_dump" example@mail.example

这篇关于Cron Job - 如何将输出文件发送到电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆