A cron can be seen as a separate user. Thus, this βuserβ may not βseeβ or βreadβ the same files as you. Therefore, it is important that all path names, etc. They were defined in absolute terms.
Each script works in its own process. So, when you run the script, you can change $SHELL and any other variable inside, but it will be lost as soon as you exit it. I assume that the calculation of the $INDEX variables may have been calculated in the script successfully, but its use outside the script may have failed. Without additional information about what kind of work was or what you wanted to do, it is difficult to say.
There are two ways to run a cron job:
- As root, you can run
su -user -c < job > in root crontab . - The distortion of your profile is clearly how you did it.
- You can also set environment variables inside crontab.
- As a user in a custom crontab, you can run it like this:
"/home/blah/.profile && myScript"
However, there should be something in your environment variables (other than file extensions) that are not present when running the cron job. You will need to execute this script using -x flag (in bash) and then process the result. Using diff between your environment variables and the root/cron parameter may be a pointer. Also, check to see if there are any utilities that are used in your scripts whose locations are not part of the $PATH variable for cron / root.
source share