space2018 Posted May 29, 2018 Posted May 29, 2018 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 Igo 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 ordirectory.Thanks in advance.
wolstech Posted May 29, 2018 Posted May 29, 2018 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.
space2018 Posted May 30, 2018 Author Posted May 30, 2018 Does this process work for shell commands? These particular maintenance scripts need to be executed from a shell. Please see (https://www.mediawiki.org/wiki/Manual:Maintenance_scripts). It is my understanding these scripts should work with cron. Sorry for not making this clear.
wolstech Posted May 30, 2018 Posted May 30, 2018 MW actually has an extension specifically for shared hosts where there's no shell or where cron is restricted (like us). You can use the extensions mentioned here to run them from a browser instead: https://www.mediawiki.org/wiki/Manual:Maintenance_scripts#No_shell_access and https://www.mediawiki.org/wiki/Extension:MaintenanceShell
space2018 Posted May 30, 2018 Author Posted May 30, 2018 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.
wolstech Posted May 30, 2018 Posted May 30, 2018 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...
jhm52 Posted January 23, 2020 Posted January 23, 2020 (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 scriptimport ostry: os.system('/usr/bin/env python3.7 /path/to/script.py') print("done")except: print("failed") Edited January 23, 2020 by jhm52
Sn1F3rt Posted January 23, 2020 Posted January 23, 2020 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now