How to run custom command running drush cron via sudo? The documentation for drush cron says:


  You should set up crontab to run your cron tasks as the same user that runs the web server; for example, if you run your webserver as the user www-data: 


I wrote a wrapper drush command to do this.  In my drush_hook_COMMAND, I call

system('sudo -i -u www-data /usr/bin/drush --uri=http://BLAH --root=BLAH cron');


This works in almost all ways.  However it does not correctly check for updates.  On my drupal status page I get


  There was a problem checking available updates for Drupal...


I've tried using drush_shell_exec instead of system, just the same.  However if I do it via drush eval, it does work:

drush eval "system('sudo -i -u www-data /usr/bin/drush --uri=http://BLAH --root=BLAH cron');"


So I'm completely baffled.  Any idea what could be different between eval and the command hook?
OK, I've finally solved my own problem.

In summary, it wasn't actually a Drush thing in the end.

In detail, my custom drush command was also fixing file permissions and ownership, as per https://drupal.org/node/244924 (because cron can sometimes create a file, and then the file may have the wrong owner/perms).  This sets the ctime on all files, and it turns out that Drupal update checking relies on the ctime.

With hindsight of course I should have done a test with the permissions line removed from my custom command, but it hadn't occurred to me it could be relevant.