When cron is completed How to get email notification and log in a file (both)
Solution 1:
Your first example sends both stderr and stdout to the file (2>&1) ; the MAILTO variable set in the cron will capture any output that is not redirected, and this combined with directing the output to the file means that no output is available for the cron to email.
I'd suggest using tee to append the output to the file as well as sending it to stdout; this answer - https://serverfault.com/a/472878/102867 - is very similar one to what you're asking to acheive.
Alternatively, follow the suggestion in the first answer, and write a wrapper script to more gracefully handle the output of the script, and you can then both log, and have the output of your script mailed
Solution 2:
Cronjob for both log & email :
Run once a month at midnight of the first day of the month: 0 0 1 * *
0 0 1 * * /home/User/script.sh > /home/User/cronlog/`date +\%Y-\%m-\%d-\%H:\%M:\%S`-cron.log 2>&1 ; mailx -s "CronJob is run successfully" [email protected],[email protected]