0

I am using a crontab to run my scripts periodically, Here is the code that I have added in crontab -e

* * * * * /usr/bin/python3 /home/mark/WORKSPACE/ep_prac/scripts/main.py > $HOME/test-cron.log 2>&1; mail -s "CronJob is run successfully" abc@gmail.com, xyz@gmail.com < /home/mark/test-cron.log

I want to mail the path of "test-cron.log" file. I am running crunch of time, searched a lot but couldnt file a relevant solution

Maroun
  • 94,125
  • 30
  • 188
  • 241
tintin
  • 35
  • 2
  • 12
  • I even did a man mail and found that mail -A is used to attach a file but am not sure how do i use it here? – tintin Feb 06 '18 at 05:46
  • `cron` will send the standard output and standard error of a job to the job's owner. Maybe just `2>&1 | tee -a test-cron.log` and rely on the built-in functionality. You can set `MAILTO` to send to a different address. – tripleee Feb 06 '18 at 09:16
  • Possible duplicate of [How do I send a file as an email attachment using Linux command line?](https://stackoverflow.com/questions/17359/how-do-i-send-a-file-as-an-email-attachment-using-linux-command-line) – tripleee Feb 06 '18 at 09:20

1 Answers1

0

Instead of sending the path, I found a way to attach the log file itself and mail it to user.

mail -A "$HOME/test-cron.log -s "Cron Job run success" xyz@gmail.com"
tintin
  • 35
  • 2
  • 12