Issue
I want to run hello.py file which contains print("Hello World")
using crontab.
For that, my hello.py has this code:
#! /usr/bin/python3
print('Hello, world!')
And, in the same folder, I have used crontab -e command to open crontab and in order to execute this file every minute, I have written:
1 * * * * ./hello.py
I have also set permissions for the file to be executable using chmod a+x hello.py
.
When I run
/usr/bin/python3 hello.py
It runs perfectly. Also, when I use only ./hello.py
, the file runs.
Why is it still not executed using crontab?
Solution
Nailed it!
Instead of using 1 * * * * ./hello.py
in crontab to set the cron running per minute , I rewrote the statement to 1 * * * * /usr/bin/python3 hello.py
.
This solved the problem!
Answered By - Abhay Bh Answer Checked By - Mary Flores (WPSolving Volunteer)