6

I frequently use drush scr for little tasks throughout my day. Sometimes these end up a proper commands in my environment, but more often they are just standalone things.

If I have @foo set up in my drush aliases with remote-host, and try to run a local script, I get

$ drush @foo scr ./foo.php 
Unable to find any of the following:                                     [error]
/home/mpd/drush/commands/core/./foo.php, /home/mpd/./foo.php

Can this command run a local script on a remote site?

  • I would think that the script needs to be installed on the remote, since really all you're doing is referencing Drush that is running on the remote server. – kyletaylored Dec 23 '13 at 21:31
  • 1
    Is the script present in your current directory? Does it have the executable flag enabled for your current user (+x)? Are you able to run drush @foo status where, @foo is the remote alias? I know these are basic questions...but it's what I thought of first. – amateur barista Dec 23 '13 at 21:38
  • For the sake of this question, yes, remote communication works and the script is on the local machine and being pathed correctly from the commands line. – mpdonadio Dec 23 '13 at 21:50
  • @amateurbarista Scripts executed with drush scr don't need to be +x unless you want to include the shebang. – mpdonadio Dec 24 '13 at 13:43
11

Nope, what you want to do is not supported. When you run drush @foo scr, it causes Drush to run your scr command on the remote system. The scr command on the remote system will then look for the script it wants to run on its own filesystem. In order to make this work, you'll need to somehow get your script on the remote system, and then run it with your remote scr command.

Note that this is different than the drush php-eval command, which takes the php code to run on the commandline. So, in theory, you could passing your php over on the commandline rather than in a file; however, in practice you may find this to be problematic due to the fact that bash is going to process your text, so you'll have to make sure that everything is properly escaped. Moving the script to execute to the target machine will be more reliable for any nontrivial script.

  • Is a patch to either php-script or php-eval to handle this situation feasible? I would be willing to tackle it if it is. I have close to twenty servers now, so consolidating as much on my local machine is a big benefit for me. – mpdonadio Dec 23 '13 at 21:54
  • 1
    I think what you are looking for is just a combination of drush rsync and drush scr. Maybe a bash alias or a drush alias to run these commands in sequence would be better? You could in theory build something that used backend invoke with method post to send your file over to the remote system, and have the receiving end write it to a temporary file. I think such a patch would be welcome, if written, but it would be quite a bit more complicated than just making the compound command. – greg_1_anderson Dec 23 '13 at 21:58
  • Look at the implementation of drush ssh, which is marked to run drush @remote ssh on the local system instead of the remote system. You would then need to read your script file locally, and call backend invoke directly to run drush ev or drush scr on the remote system. You might be able to get drush_invoke_process to work; that would be easier, but I don't know that it provides enough control. Post to the issue queue if you need help with your patch. Or just go with rsync + remote drush scr. – greg_1_anderson Dec 23 '13 at 22:05

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.