skip to Main Content

I have a python file which is created on windows which is also working on ubuntu OS aswell. I have a VPS in hostinger platform where this script should run in daily basis. But triggers on the scheduled period is not happening.

I have created a Cronjob using the command

crontab -e

the Cron syntax used:

* 12 * * * python filpath/script.py

but the file is not getting executed. I have checked the system logs their is nothing related to cron jobs. Am not sure where things went wrong.

2

Answers


  1. Try this line in cron tab:

    0 12 * * * /usr/bin/python /path/to/file/script.py /path/to/file/script.log
    
    Login or Signup to reply.
  2. You incorrectly assume working directory will be the same for cronjob that is for your current session in i.e. shell. It will not. You need to change that in cron or use absolute path to your script. The former sounds better for me as I assume your scripts might have troubles working properly otherwise:

    * 12 * * * cd "<PATH/TO/YOUR/PROJECT>" && python filpath/script.py
    

    assuming your script.py lives in filpath folder located in <PATH/TO/YOUR/PROJECT>.

    You stil can have the same problem with python itself, but it’s more likely that it will be in PATH cron uses (you can change that to absolute path). BTW: when cron job fails, then you (I mean the user on which account the cron is running) shall receive a system mail with more detailed error. So check that too if you can access it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search