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

前端 未结 4 1413
情书的邮戳
情书的邮戳 2020-12-13 13:43

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)

4条回答
  •  抹茶落季
    2020-12-13 14:18

    If you want to store your cron job's output on the file on server and also want to send that output file to your mail address then you can use below command.

    And you can use it on cronjob to automatically run on specific interval of time, here i am dumping mysql db and sending it to my mail with attachment of dumped sql file.

    * * * * * mysqldump --user username --password='p@ssword' DBNAME | gzip > /home/user/db_backup/db_backup_`date +\%d-\%m-\%Y-\%H-\%M`.sql.gz && mailx -a /home/user/db_backup/db_backup_`date +\%d-\%m-\%Y-\%H-\%M`.sql.gz -s 'database backup date:'`date +\%d-\%m-\%Y-\%H:\%M` example@gmail.com
    

提交回复
热议问题