/ tech-note

How to access an internal file of a script run by a cron job?

I have failed to access a file that should be accessed in a script run by a cron job.

The problem came from the fact that the cron job could not access the internal file due to a different path.

So you must make sure to write the file in a program in an absolute path. This is simple in Python.

For example, if you run a script in a cron job called main.py and access the main.sql in the file, write main.sql in an absolute path.

import os
filename = "main.sql"

dir_path = os.path.dirname(os.path.abspath(__file__))
abs_path = os.path.join(dir_path, filename)

Source: http://stackoverflow.com/a/10422444/2360798