I am wondering if there is a way to dynamically populate the time of a cron job off of an environment variable. For example:
export JOB_MINUTES=4
Then in the crontab
$JOB_MINUTES * * * * /tmp/my_script.sh
Resulting in a crontab of
4 * * * * /tmp/my_script.sh
Environment variables aren't expanded inside the crontab file. But you can use the environment variable when you're creating the crontab file, by piping an echo command to crontab.
{ crontab -l ; echo $JOB_MINUTES * * * * /tmp/my_script.sh; } | crontab -
The - filename argument means to get the crontab contents from standard input.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With