Using Drush to get a quick list of available updates

I'd been looking for a way to get an email report of available module and theme updates on a growing collection of drupal sites.

The traditional way to do this is to bop around to the admin/reports/updates page for each of the sites. This can be fun to do, of course, but a bit time consuming.

I figured that drush, the most essential MacGyver tool for any drupuler, would make short work of this, and indeed, it does. Enter:

drush up -n | grep available

and you'll get something that looks a bit like this:

 LoginToboggan     6.x-1.8   6.x-1.9    Update available                         
 Node Hierarchy    6.x-2.x-  6.x-2.x-   Update available                         
 Views             6.x-2.9   6.x-2.12   SECURITY UPDATE available

Cool! A nice concise list of updates and security updates (I temporarily threw in an old version of views, just to make sure security updates would indeed show up).

What's happening here? Let's break it down:

drush up this is the standard drush "upgrade my codebase" command.
-n tells drush to answer "no" to any prompts that come up - this basically exits out of the upgrade process - this is crucial, because you probably don't want to automatically upgrade your site!
| grep available this takes the long list of updates, and filters for lines containing the word "available" - because those are the ones we want to see!

OK, so that's how the basic command works. Next we'll have to do a couple things to get it to work as a cron job.

Depending on how you set up drush initially, you'll likely have to include the full path to drush, as well as specify the root of your site with --root. Easy enough:

full/path/to/drush/ up -n --root=/full/path/to/drupal/site | grep available

Drop this command into a cron job, set it up to email you a report, and you're good to go.

I'd be surprised if there weren't several ways to do this, so let me know in the comments if you've got a strategy that you prefer.

- I <3 drush image from: http://didier.misson.net

Tags:
drush tips