0

I want to run some maintenance scripts against a Drupal 7 system. These scripts will call the Drupal API to use things like EntityFieldQuery, node->save and so on. I could create a module called maintenance_scripts which has a forms interface to launch the scripts with and to display their output, but I'd rather just run a script from the command line. Is this possible?

4
  • Using drush you can create your custom commands it's very easy. sitepoint.com/drupal-create-drush-command – ropic Apr 28 '16 at 21:22
  • That's a great article thanks. So I'd have to create a whole new module (with all the required infrastructure of .info files etc), or add hooks into an existing module, in order to run my Drush script? Is there any easier way? – Monkeybrain Apr 28 '16 at 21:28
  • If you want to create a stand-alone Drush script, you can put it in ~/.drush, or in __DRUPAL_ROOT__/drush. Don't forget to run drush cc drush after creating a new Drush command; otherwise, Drush won't refresh its cache of command file locations, and your new command will not be found. – greg_1_anderson Apr 28 '16 at 21:34
  • You can use an existing module you have developed. – ropic Apr 28 '16 at 21:55
4

It is not necessary to write an entire Drush command just to run some php code. Use:

drush php-eval '$a = callSomeFunction(); print $a;'

or:

drush php-script /path/to/script.php

Drush will bootstrap your site and run your code.

0

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.