Community Documentation

Run cron.php with python.

Last updated August 27, 2011. Created by davebv on December 13, 2008.
Edited by spuky. Log in to edit this page.

I was unable to run cron.php from the cpanel cron on a multisite because I had no access to curl, lynx and wget. I knew I had python installed in the shared server so what I did was to create a python script in my home folder called wget.py

Python 2 Version:

import sys, urllib
def reporthook(*a): print a
for url in sys.argv[1:]:
     i = url.rfind('/')
     file = url[i+1:]
     print url, "->", file
     urllib.urlopen(url)

Python 3 Version:
#!/path/to/python3
import sys, urllib.request
def reporthook(*a):
    print (a)
   
for url in sys.argv[1:]:
     i = url.rfind('/')
     file = url[i+1:]
     print ("%s %s %s" % (url, "->", file))
     # urllib.urlretrieve(url, file, reporthook)
     urllib.request.urlopen(url)

Then, in the cron configuration, just add the command:

/path/to/python /path/to/wget.py url1/cron.php url2/cron.php url3/cron.php
AttachmentSize
wget.py_.txt218 bytes