Issue
I have a shell script that sets up our crontab on AWS EMR.
The shell script is run as part of EMR steps setup.
However when it excecutes it is evaluating the date directly and not the text as is which is what I want as that cronjob will be run dynamically based on yesterday's date
My script crontab portion
crontab -l && echo "0 20 * * * python app.py --date=$(date -d "yesterday" +\%Y-\%m-\%d) >> app.log 2>&1") | crontab -
Pasted manually in emr it shows like original which is what I want but now I want to automate the cron setup
The EMR step scripts executes this shell script and evuluates the environment variable to the true value like so:
crontab -l && echo "0 20 * * * python app.py --date=2020-01-16 >> app.log 2>&1") | crontab -
This is not what I want as now my cron will only run this for that set date.
How can I make it so that the script's environment variable is not evaluated and kept as is format?
Solution
Replace the double-quotes with single-quotes to keep the $(date...)
from being expanded when the echo
is run.
Answered By - Kurtis Rader