1

How to execute system cron manually via drush or drupal UI?

  • 1
    To confirm you just want to run the one cron hook and not the others? – mpdonadio Nov 17 '16 at 14:45
  • to be specific about my requirement, I want to execute the cron that deletes the unused or not-permanent files. – meen Nov 18 '16 at 11:11
3

To execute just the system_cron() hook, the easiest way is with drush

$ drush php-eval 'system_cron();'

This will start a PHP process, boostrap Drupal, and run the input. Note that this will run everything that this hook does, in addition to the file cleanup, including garbabe collection on the various database tables with ephemeral data, like {cache}, {batch}, {flood}, etc. There isn't an individual function in Drupal 7 that just handles the file cleanup.

Also keep in mind that when you run drush like this, you are running as the user who you logged in as. This user may or may not have persmissions on the files and tmp directories in order to delete files.

You could copy this code into your own script and then do

$ drush scr cleanup-the-files.php
  • Thanks :) One more question I have is where can I get the history of cron executed? i.e. past all times when it got executed – meen Nov 21 '16 at 8:07
  • 1
    @meen When the full cron runs, it will create an entry in {watchdog}. So, if that is enabled on your site, you will see it in the Recent Log Messgaes. If you run a cron hook individually, like I show above, it may or may not get logged. system_cron() doesn't log anything, unless it has problems deleting system files. – mpdonadio Nov 21 '16 at 14:11
2

You can try drush core-cron it will do the trick

  • Don't know how but it worked first time. but when tried again twice it didn't. – meen Nov 18 '16 at 6:18
0

Go to Configuration->System->Cron Settings(admin/config/system/cron), you can see system_cron listed here. Execute this cron by clicking on run link corresponding to the same.

  • system_cron not listed. – meen Nov 18 '16 at 6:17
  • Ok. So can u please confirm any other crons are listing there? If not it may be any permission issue.. Please try below URL YOUR_SITE_URL/admin/config/system/cron/execute/system_cron – Aswini K Nov 18 '16 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.