Run python in Cron Job

6 posts / 0 new
Last post
#1 Tue, 02/20/2018 - 10:20
pratam02

Run python in Cron Job

Hello,

is it possible to run python file (.py) in cron job?? if yes, then can you provide the syntex which i have to follow to make it run in virtualmin??

I am trying to run job by using python script.... it will check some status in multiple tables and sends emails based on conditions....

need help in configuring it in Virtualmin.

or if Virtualmin have any setup already then please let me know....

Regards Praveen

Tue, 02/20/2018 - 20:15
unborn
unborn's picture

hi, well python can run outside of anything...just run the cron job as usual in any linux distro, precisely said, you dont even need virtualmin to run your crons.. regards how to run it, google is flooded with info.

Configuring/troubleshooting Debian servers is always great fun

Thu, 03/01/2018 - 12:53
pratam02

Hi Unborn,

thanks for the info....

I am trying to use webmin feature of scheduling cron job as per below link. https://www.virtualmin.com/documentation/tutorial/how-to-setup-a-cron-job

I created job and executed by clicking "Run Now" button and everything worked well, but when I scheduled it to run... its not working.... in the commend field I just placed like this - > python \folder1\folder2\file.py... (as i said when I run immediately it works great...)

what I am doing wrong here....

Regards Praveen

Tue, 03/06/2018 - 05:20
unborn
unborn's picture

Hi Praveen,

I would check the user you running the cron job under.. it should be domain owner (try to avoid root user unless you have to run that job under root user). also you can explicitly use /usr/bin/python in your crontb command... aka: /usr/bin/python /path/to/your/script.py - that should make it working.. also check your shebang but, I guess it is correct.

Edit: attaching screenshot how might simple cron job schedule looks like in virtualmin... (working one)

screenshot - full size: https://i.imgur.com/Q4NYtQV.png

Configuring/troubleshooting Debian servers is always great fun

Sat, 03/17/2018 - 19:30
pratam02

Thank you...

that helped...

Providing full path of python resolved issue....

Regards Praveen

Tue, 10/02/2018 - 06:31
unborn
unborn's picture

@pratam02

  • I am glad to helped :)

Configuring/troubleshooting Debian servers is always great fun

Topic locked