I am trying to run some commands on a remote server. I need to source some bash files there. Unfortunately, it seems fabric has (suddenly, recently?) started using /bin/sh
, and it breaks because I use bash syntax in my scripts. I have found this:
If shell is True (the default), run will execute the given command string via a shell interpreter, the value of which may be controlled by setting env.shell (defaulting to something similar to /bin/bash -l -c "".) Any double-quote (") or dollar-sign ($) characters in command will be automatically escaped when shell is True.
I have not changed env.shell, so I do not know why fabric starts using sh
. In any case, I am overwriting it, but still no luck:
env.shell = "/bin/bash"
What could be causing this? What can I do to force fabric to use bash
?
It took some digging, but this is what I found:
It is possible to see what fabric is doing behind the scenes:
from fabric.api import output
FAB_SHOW_RUNNING = True # Show the command that fabric runs
FAB_SHOW_STDOUT = False # Show the stdout of the command run
FAB_SHOW_STDERR = False # Show the stderr of the command run
FAB_SHOW_DEBUG = True # Increase logging detail for messages
FAB_SHOW_USER = True
FAB_SHOW_STATUS = False # Prevent fabric from using print in some situations (at least in disconnect_all)
FAB_SHOW_WARNINGS = False # Avoid fabric from showing messages about failed commands
output['running'] = FAB_SHOW_RUNNING
output['stdout'] = FAB_SHOW_STDOUT
output['stderr'] = FAB_SHOW_STDERR
output['debug'] = FAB_SHOW_DEBUG
output['user'] = FAB_SHOW_USER
output['status'] = FAB_SHOW_STATUS
output['warnings'] = FAB_SHOW_WARNINGS
It turned out it is not fabric using /bin/sh
but, since I was (in this particular case) running local commands, the culprit was the subprocess module. In order to specify the shell to be used, you need to specify shell=True
and executable='/bin/bash'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With