1

I would like to drush enable a bunch of modules in a certain environment via a shell script that runs EVERY TIME the environment rebuilds when new code is committed. (This saves me from having to have access to a drush terminal when I want to first install a module in an environment, but means I don't know if module is being enabled for the first time or if it was enabled long ago)

I'm concerned there might be consequences of repeatedly enabling already enabled modules. Is this true?

If yes, I'm trying to find a drush command to enable a module only if it's not already enabled.

For example, I have seen this page:

drush en `drush pm-list --status="disabled,not installed" --pipe`

which enables all disabled modules.

and

drush dis `cat tmp.txt` --yes

which disables all modules listed in tmp.txt

I want something like:

drush en `magicfunction(tmp.txt, `drush pm-list --status="disabled" --pipe`)`

where magicfunction is some linux command line magic that returns the names of modules listed in tmp.txt that are also in the list of not enabled modules.

Any ideas?

  • 3
    If you run drush pm-enable some_already_enabled_module, drush will simply skip it. So there is no harm there, just list all modules you need. Drush will take care of it. It simply responds with a message module_name is already enabled. – Neograph734 May 15 '16 at 19:12
  • The only reason to do something like this, would be for performance optimization, if you are doing this a lot of times – googletorp May 15 '16 at 19:37
1

You can use grep command to filter out the modules from disabled list to only which are appearing to your list, e.g.

drush -y en $(drush pm-list --status="disabled" --pipe | grep -f tmp.txt)

Other way is to use SQL query:

drush -y en $(drush sqlq "SELECT name FROM system WHERE name IN ('$(cat tmp.txt | paste -sd, | sed "s/,/','/")');")

which may be more complex, but quicker (especially when you replace drush sqlq with mysql -e command.

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.