Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
433 views
in Technique[技术] by (71.8m points)

crontab - Cron Job - How to send an output file to an email

I have this line in crontab:

* * * * * /var/www/dir/sh/mysql_dumb.sh | mail -s "mysql_dump" [email protected]

(every minute only a sample)

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

UPDATE:

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

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

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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" [email protected]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...