Pages

Unixbhaskar's Blog

Tuesday, April 19, 2011

Drush: A command line Drupal site manipulator

In this article I will touch a software called Drush, which essentially do the things like gems do for Ruby or easy_install does for python.

I have installed drupal and using this command line utility I will show you how you can get things going on drupal without going into the web interface.

So here we go:

I am assuming drush has been installed in the GNU/Linux box by you people already;if not get it installed.Say I need to know the status of php conf file and drush version ;here is how you can get it:



bhaskar@bhaskar-laptop_15:34:32_Tue Apr 19:~> sudo /usr/bin/drush status
[sudo] password for bhaskar:
PHP configuration : /etc/php5/cli/php.ini
Drush version : 3.3



Now if you want know the backend database information,then do



bhaskar@bhaskar-laptop_15:45:12_Tue Apr 19:/var/www/drupal> sudo /usr/bin/drush sql-conf
Array
(
[driver] => mysql
[username] => drupal
[port] =>
[host] => localhost
[database] => drupaldb
)




Right..cool ,now say you are curious to know modules comes with drupal about their status:



bhaskar@bhaskar-laptop_15:45:14_Tue Apr 19:/var/www/drupal> sudo /usr/bin/drush sm
Package Name Type Status Version
CCK Content (content) Module Enabled 6.x-2.9
CCK Content Copy (content_copy) Module Enabled 6.x-2.9
CCK Content Permissions (content_permissions) Module Enabled 6.x-2.9
CCK Fieldgroup (fieldgroup) Module Enabled 6.x-2.9
CCK Node Reference (nodereference) Module Enabled 6.x-2.9
CCK Number (number) Module Enabled 6.x-2.9
CCK Option Widgets (optionwidgets) Module Enabled 6.x-2.9
CCK Text (text) Module Enabled 6.x-2.9
CCK User Reference (userreference) Module Enabled 6.x-2.9
Core - optional Aggregator (aggregator) Module Enabled 6.20
Core - optional Blog (blog) Module Enabled 6.20
Core - optional Blog API (blogapi) Module Enabled 6.20
Core - optional Book (book) Module Not installed 6.20
Core - optional Color (color) Module Enabled 6.20
Core - optional Comment (comment) Module Enabled 6.20
Core - optional Contact (contact) Module Enabled 6.20
Core - optional Content translation (translation) Module Not installed 6.20
Core - optional Database logging (dblog) Module Enabled 6.20
Core - optional Forum (forum) Module Enabled 6.20
Core - optional Help (help) Module Enabled 6.20
Core - optional Locale (locale) Module Not installed 6.20
Core - optional Menu (menu) Module Enabled 6.20
Core - optional OpenID (openid) Module Enabled 6.20
Core - optional Path (path) Module Enabled 6.20
Core - optional PHP filter (php) Module Enabled 6.20
Core - optional Ping (ping) Module Enabled 6.20
Core - optional Poll (poll) Module Enabled 6.20
Core - optional Profile (profile) Module Enabled 6.20
Core - optional Search (search) Module Enabled 6.20
Core - optional Statistics (statistics) Module Enabled 6.20
Core - optional Syslog (syslog) Module Enabled 6.20
Core - optional Taxonomy (taxonomy) Module Enabled 6.20
Core - optional Throttle (throttle) Module Enabled 6.20
Core - optional Tracker (tracker) Module Enabled 6.20
Core - optional Trigger (trigger) Module Enabled 6.20
Core - optional Update status (update) Module Enabled 6.20
Core - optional Upload (upload) Module Enabled 6.20
Core - required Block (block) Module Enabled 6.20
Core - required Filter (filter) Module Enabled 6.20
Core - required Node (node) Module Enabled 6.20
Core - required System (system) Module Enabled 6.20
Core - required User (user) Module Enabled 6.20
Other Bluemarine (bluemarine) Theme Disabled 6.20
Other Chameleon (chameleon) Theme Disabled 6.20
Other Garland (garland) Theme Enabled 6.20
Other Marvin (marvin) Theme Disabled 6.20
Other Minnelli (minnelli) Theme Disabled 6.20
Other Pushbutton (pushbutton) Theme Disabled 6.20



Let's say you want to install some module right? Go ahead and install it like below:



bhaskar@bhaskar-laptop_15:48:23_Tue Apr 19:/var/www/drupal> sudo /usr/bin/drush dl diff
Project diff (6.x-2.1) downloaded to /var/www/drupal/sites/all/modules/diff. [success]



Here I have installed a module called "Diff",which basically do adds a tab for sufficiently permissioned users. The tab shows all revisions like standard Drupal but it also allows pretty viewing of all added/changed/deleted words between revisions.

But installing module will not sufficient, we need to activate or enable them, so you need to do like below:


bhaskar@bhaskar-laptop_15:51:41_Tue Apr 19:/var/www/drupal> sudo /usr/bin/drush en diff
The following projects will be enabled: diff
Do you really want to continue? (y/n): y
diff was enabled successfully. [ok]



Cool...isn't it!!! Now we are going to refresh the database from command line like below;



bhaskar@bhaskar-laptop_15:55:03_Tue Apr 19:/var/www/drupal> sudo /usr/bin/drush rf
Refreshing update status information ...
Done.



Last but not the least to run a cron related to drupal like below:



bhaskar@bhaskar-laptop_15:58:01_Tue Apr 19:/var/www/drupal> sudo /usr/bin/drush cron
Cron run successfully. [success]




Hope this will help.

Cheers!
Bhaskar