Jump to content

Help with Crontab

Nicnac

So I want to run a python script every 4 hours every day.

From what I got out of the documentation that would look like this:

 

0 0,4,8,12,16,20 * * * /home/user/Projectdirectory python script.py

 

and this line is what I simply put into the crontab file using

crontab -e

 

How can I check if the crontab is running and if this works? Is this even the right way to do it?

 

Folding stats

Vigilo Confido

 

Link to comment
Share on other sites

Link to post
Share on other sites

It should be:

0 */4 * * * ./home/user/Projectdirectory/script.py

or if you're using python2

 

0 */4 * * * /usr/bin/env python2 /path/to/script.py

 

 

https://askubuntu.com/questions/799023/how-to-set-up-a-cron-job-to-run-every-10-minutes

Current Network Layout:

Current Build Log/PC:

Prior Build Log/PC:

Link to comment
Share on other sites

Link to post
Share on other sites

8 minutes ago, Nicnac said:

So I want to run a python script every 4 hours every day.

No, you're not running the script correctly and there's also an easier way of telling cron to run something at certain intervals:

0 */4 * * * /usr/bin/python /home/user/Projectdirectory/script.py

 

Or the following if you use python3:

0 */4 * * * /usr/bin/python3 /home/user/Projectdirectory/script.py

 

You can also just execute the script.py directly, if you make it executable with chmod u+x script.py and add #!/usr/bin/python as the first line in the file.

Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to comment
Share on other sites

Link to post
Share on other sites

@Lurick @WereCatf Thanks guys! I am using python2 

I heard that sometimes there can be issues with the /version so I thought it would be safer the other way. So I first have to navigate to the python directory and then simply to the script? 

Also, just putting that one line into the crontab file will do it, right?

sorry pretty noob to all this

Folding stats

Vigilo Confido

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×