I have a python script (script A) that runs multiple sub-processes (running another python script - script B). When I run the script manually, it works fine, but when it is being run using crontab it behaves differently. To be more specific, my script is limited to 100TB of quota, so script B runs over a tree and produce a text file of size-per-dir. This script is being run multiple times on several dir-trees as a subprocess, and the results are being further analyzed by script A. When I run manually, both scripts run fine. But when I run it using Cron, script A runs fine but script B produce odd resutls. Any ideas of why using Cron would affect a python script?
Asked
Active
Viewed 140 times
0
-
crontab uses a stripped down environment, and a limited path. That means that: 1/ command may not be found if they are not prepended with their full path 2/ programs finding elements in the environment may not find them. More details in [that other post](https://stackoverflow.com/q/2229825/3545273) – Serge Ballesta May 29 '18 at 09:18
2 Answers
0
Make sure the crontab you are using is with full path of the .sh
file.
And in beginning of your script try to add the following:
. /home/gemapp/.bash_profile
to load all needed items in bash_profile
.

Ivan Vinogradov
- 4,269
- 6
- 29
- 39

Pedram Ezzati
- 325
- 3
- 16
0
The default directory for any scheduled job is user's home dir, not the location of the shell script/program itself.
To mimic the crontab job, you must simulate running your script from user's home dir using "cd ~" command. Run your job using the exact same syntax as in your "crontab -l" output to simulate the error.
In other word, you must simulate running your schedule job from home dir. Once it worked, then you put it into the crontab.

SCChen
- 31
- 2