Jump to content

Recommended Posts

Posted

I'm trying to run PHP maintenance scripts on my site using cron in cPanel, which imposes a limit of 2 cron jobs per day (i.e. one every 24 hours), which is fine. Due to this limitation, how do I
go about debugging & testing cron jobs?

If I test-run the scripts, I will easily exceed the limit? It would be time consuming to wait 12 hours to test a script that previously failed due to a syntax error such as a wrong path or
directory.

Thanks in advance.

 

Posted

As long as it's somewhere inside your public_html folder, you can just visit the script in your browser to trigger the script, and the output will appear on the page.

 

I personally would recommend setting a 

header("Content-Type: text/plain");

at the top of the script so the browser doesn't mangle the output for testing.

 

If it's not in public_html, you'll need to move it there, then do the above.

Posted

Thank you, I am aware of those extensions but they haven't been updated for years, are not officially supported by MediaWiki and cannot schedule tasks. My intention was to use cron to schedule the "maintenance" tasks on a daily, or weekly basis. But first, I wanted to run the scripts to make sure they actually worked.

 

It is my understanding that Python CGI scripts can execute shell commands (see: https://www.helionet.org/index/topic/29129-python-script-behavior/?hl=python) Could an admin please advise if this is a possible solution on Heliohost?

 

I greatly appreciate your response.

Posted

I don't see any reason it wouldn't work, but I can't guarantee it. Python should have the ability to spawn processes under your user account though (unlike PHP...), so it's definitely something to explore. You'll need to adapt the scripts to fetch the output for you if you care about it, as the ones in that example only parse the output of ps to see if its already running. 

 

We have a user Bailey who is really good with MediaWiki too, perhaps he has an idea on this. He was working on rebuilding our Wiki a while back...

  • 1 year later...
Posted (edited)

I had the same issue and couldn't debug the cron job to run a python script. at the end I created a python script which execute shell command then  I placed in a public folder with permission 755, you need to open it in a browser for the script to be executed.

the script is as follow:

#!/usr/bin/python3.7
 
print("Content-Type: text/html\n\n")
 
print("This will show if python is executing properly")
#replace /path/to/script.py with the path to your own script
 
#the below allow to execute shell script
import os
try:
    os.system('/usr/bin/env python3.7 /path/to/script.py')
    print("done")
except:
    print("failed")
Edited by jhm52
Posted

I think it should be this though:

#the below allow to execute shell script
import os
try:
    os.system('/usr/bin/python3.7 /path/to/script.py')
    print("done")
except:
    print("failed")
Cuz the path to the Python compiler is /usr/bin/python3.7

 

Also, check your line endings in that line : print("Content-Type: text/html\n\n")

 

Open it using Notepad++ and go to Edit > EOL and check that it's selected to Unix. Otherwise, if it's Windows change it to Unix and the problems should be sorted.

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
×
×
  • Create New...