2

Trying to set up a couple of cron jobs in cPanel but since the system uses commandline for crons I can´t use parameters - this is a wordpress cron and relies on parameters in url.

How can i get this to work through commandline?

php -q /home/facebnzc/public_html/folkeuniversitetet/wp-cron.php?import_key=NAbeK7X&import_id=1&action=processing
BeTA iT
  • 99
  • 1
  • 7
  • 4
    command lines have absolutely **NO** knowledge of urls. `?` will be seen as a shell widlcard, and you'll get "no match", `&` will be a job control operator, and put your entire php command into the background, blah blah blah. The command line has absolutely **NOTHING** to do with the web, and you cannot expect web addresses to mean anything to the shell. – Marc B Jun 20 '14 at 21:20
  • 1
    maybe this helps: http://stackoverflow.com/q/8558041/367456 - the basic idea is that you use the cron command to do the web-request for you. normally this is done with curl or wget, some cpanels allow you to specify a webrequest for their "kind of" cron as well. – hakre Jun 20 '14 at 21:26

1 Answers1

3

This constant just enables or disables the check for events that are ready to fire. You still add and manage events as we did up above. We just need to manually hit the wp-cron.php file in our WordPress install often enough to fire our scripts when needed.

If all you have are daily scripts, you can add a cron job like this via the crontab -e command:

0 0 * * * wget -O - -q -t 1 http://yoursite.com/wp-cron.php?doing_wp_cron=1

Information on how to use cron can be found at its Wikipedia entry. Information on how to use wget can be found at the wget manual.

The 0 0 * * * part of the preceding entry tells cron to execute this script at 0 minutes on the 0th hour (midnight) every day of the week.

The wget -O - -q -t 1 http://yoursite.com/wp-cron.php?doing_wp_cron=1 part uses the wget command to load up the wp-cron.php page in your WordPress install. The -O - tells wget to send output to devnull, and the -q enables quiet mode. This will keep cron from adding files to your server or emailing you the outputs of each cron run. The -t 1 tells cron to try once. This will keep wget from hitting your server multiple times if the first try fails. If the call to wp-cron.php is failing, the rest of your website is probably failing too; hopefully you’ve already been notified.

Be sure to change yoursite.com to your actual site URL. And finally, the ?doing_wp_cron=1 on the end of the URL is needed since wp-cron.php will check for that $_GET parameter before running.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103