I am trying to set up a cronjob in my Apache2/Ubuntu 20.04 server.
The python file that I want to execute is as follows:
def main():
print('TEST')
function()
def function():
file1 = open("home/username/project/cron_test.txt","a")
str1 = 'Test2 \n'
file1.write(str1)
file1.close()
if __name__ == '__main__':
main()
I have defined my cronjob as follows:
* * * * * /home/username/project/venv/bin/python3 /home/username/project/cron_test.py
When I run the command in putty, it works perfectly fine, and I get my desired output. However, when I place it in the crontab, the python script doesn't run.
Any ideas what I am doing wrong? I have tried various different ways, such as cd into the project folder and then run it, as well as putting a -f in between the python venv and the code, but I don't get any closer.
Help is appreciated.
Best regards,
Patrick