Writing script runs to tmp file with hour_seconds file name

I'm trying to make sure my cron task is executing every minute, I want to record the output of every run into a location in /var/tmp.

This is how my cron file looks like :

hours_minutes_file=/var/tmp/moo_tools/runs/`date +"%H_%M"`
* * * * * /bin/bash -l -c 'cd /home/power_user/apps/transactional_processing/current && RAILS_ENV=production bundle exec rake moo_tools:process_records --silent ' > "$hours_minutes_file" 2>&1 

The result file does not look like I was expecting. I was expecting to see files like /var/tmp/moo_tools/runs/00:11 where 00 would be the hours of the day and 11 would be minutes.

Instead I am getting file names like this (I created 00_33 and 00_34 manually) :

ls /var/tmp/moo_tools/runs/
 00_33   00_34  '`date +"%H_%M"`'

What am I doing wrong? Why is the string substitute not "kicking in"? I tried using "${hours_minutes_file}" instead but that didn't work too. Bash beginner here, not sure how to fix this.


hours_minutes_file is set by cron, not by a shell. Cron doesn't interpret backticks or braces ({ }), which then become part of the file name.

I would put the logic including the creation of that output file into a shell script and execute the script from cron. As a desirable side effect, you get a cleaner crontab.