Generally, when I need to use Environmental Variables in a Cron job, I just declare them in the cron tab. However, Im working on a server where I don’t have direct access to the the cron tab. I was told I can use a bash script to set the variables for the cron job. I’m not too familiar with bash, and I’m not quite sure what the flow of commands is.
My cron job is going to execute a Php script once a week. So I need a separate cron job to run a bash script? What would this bash script look like?
If you don’t have access to change the crontab, then you have to change the PHP script. You have to change one or the other.
You can replace the PHP script with a bash script that sets the environment variables and then calls the PHP script in its new home. But then you have to move the PHP script and give the bash script the PHP script’s old name.
At least, that is the case unless you can have the cron job modified to call the bash script instead of the PHP script. But if you can do that, I don’t know why you can’t have the environment variable setting added.
In any case, there’s no way a separate script run independently can set environment variables on behalf of the cron job.