0

I have the following command that works well when I execute it manually :

sendreport --date_start=`date +%Y-%m-19 -d "-1 month"` --date_end=`date +%Y-%m-19` --to=myemail@mydomain.ch

My problem is when I execute the same command via cron task, nothing happens. If I replace the part that set the date dynamically, by an actual date, then the cron works. For example, this works on cron :

sendreport --date_start=2017-12-19 --date_end=2018-01-19 --to=myemail@mydomain.ch

Also tried this way, and again it works if I execute it manually, but nothing happens if it is cron :

sendreport --date_start=$(date +%Y-%m-19 -d "-1 month") --date_end=$(date +%Y-%m-19) --to=myemail@mydomain.ch

Finally, also tried declaring the value of dates in variables, and again cron won't work.

The script sendreport is receiving empty value for date parameters when executed by cron.

Thank you in avance for your help.

  • Are the dates being evaluated when you enter the command instead of when it runs? What does `crontab -l` show? Any useful information in syslog or cron.log? – Andrew Schulman Jan 16 '18 at 17:32
  • The dates are no evaluated (not sown in console). Crontab -l shows me the cron task exactly as I created it. I can see the in syslog the command is being executed at the time setted in crontab. – Dayron Gallardo Jan 16 '18 at 18:46
  • Escaping the % and double quotes solved the problem. After many years using cron, I'm surprised never run into this before! – Dayron Gallardo Jan 17 '18 at 16:16

0 Answers0