SSH runner shell expansion?

Hi everybody! :slightly_smiling_face: :

I’m using Drone’s new SSH runner (it’s really good!), but I’m having some trouble where a command involves some bash shell expansion. In particular, trying to restart a bunch of services like systemctl --user restart server@{1..8}.service does not seem to work? Must I escape it, or is there another way to do what I want? How would I go about doing that?

Thank you all so much in advance! :slightly_smiling_face:

systemctl --user restart server@{1…8}.service

Drone would not make any changes to this command since it is not a bash variable (does not match ${variable} syntax), so there is no need to escape anything. Drone takes the above command and generates a shell script, uploads that shell script to your server (using sftp) and then executes it. The generated shell script looks something like this:

#!/bin/sh

systemctl --user restart server@{1..8}.service

Unfortunately we do not really have the full details details (error message, steps to reproduce, etc) so it is difficult for me to advise on possible root causes without speculating. However, one common root cause we see is that sometimes people use bash syntax which may not be compatible with sh, or may not be compatible with the version of sh installed on the target machine.

Oh, I did not know that. Thank you! :slightly_smiling_face:

And I was talking about shell expansion, so things like {1..3} would convert to 1 2 3, etc. It seems the bare bones shell does not support it, which is a shame :confused: Is it possible to change the default shell back to bash?

Is it possible to change the default shell back to bash?

to ensure posix compliance Drone will always use sh but you can always execute bash commands or even invoke a bash script from your pipeline.

For example like this:

kind: pipeline
type: ssh
name: default

steps:
- name: restart
  commands:
  - bash -c "systemctl --user restart server@{1..8}.service"

Or like this:

kind: pipeline
type: ssh
name: default

steps:
- name: restart
  commands:
  - bash restart.sh

Or even this may work:

kind: pipeline
type: ssh
name: default

steps:
- name: restart
  commands:
  - echo "systemctl --user restart server@{1..8}.service" > restart.sh
  - bash restart.sh