Hi everyone,
I wrote a script that is supposed to be run by cron on a daily basis. It works just fine if I run it manually, but due to a lack of environment variables (which are available during my user session but not when cron runs the script) it keeps failing to run successfully.
Here's the complete scenario:
The run_lines.sh script executes the lines.sh script 6 times, each one with different parameters, like this:
run_lines.sh:
#!/bin/bash
/home/me/lines.sh 04 email1@mydomain.com
/home/me/lines.sh 05 email2@mydomain.com
/home/me/lines.sh 06 email3@mydomain.com
(Only 3 lines are shown above)
And here's the crontab entry:
15 08 * * * /home/me/run_lines.sh
Now here's what I'm thinking. I created a list of the environment variables that are available to my user session with:
env > env_user.log
Then I'm thinking about doing this in one of the scripts mentioned above (run_lines.sh or lines.sh):
while read line; do
export $line
done < env_user.log
That way when the script is run through cron, all the environment variables of my user session will be exported and made available to cron.
I also tried
15 08 * * * me /home/me/run_lines.sh
but my implementation of cron does not seem to allow that.
I've done it before but I'm not quite sure it's the most efficient way to go.
Any hints or ideas will be more than welcome.
Thanks in advance.