ssh-action: Some commands don't work

err: bash: -c: line 3: syntax error near unexpected token `('
2020/02/09 17:57:24 Process exited with status 1
err: bash: -c: line 3: `sudo rm -r /usr/dotnetapps/bugsincluded/!(*.db*)'

This is a valid linux command that removes all files and folders that don’t match the pattern, it works when I run it manually on my server, but it doesn’t work using this ssh-action tool.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 34 (10 by maintainers)

Most upvoted comments

@MahbbRah

this issue is about interactive vs non interactive shell.

you can check this at: https://askubuntu.com/questions/247738/why-is-etc-profile-not-invoked-for-non-login-shells

basically, if you are running a command in a non interactive shell, like ssh-action, on many linux distros,

“/etc/bash.bashrc” file has a specific command that returns only, so some of the files didn’t run and some specific commands doesn’t add to path,

# /etc/bash.bashrc
# System-wide .bashrc file for interactive bash(1) shells.

# To enable the settings / commands in this file for login shells as well,
# this file has to be sourced in /etc/profile.

# If not running interactively, don't do anything
[ -z "$PS1" ] && return`

just comment out the line that returns early and everything should work fine, or you can use the real paths of the commands that you would like to use.

@MahbbRah

this issue is about interactive vs non interactive shell.

you can check this at: https://askubuntu.com/questions/247738/why-is-etc-profile-not-invoked-for-non-login-shells

basically, if you are running a command in a non interactive shell, like ssh-action, on many linux distros,

“/etc/bash.bashrc” file has a specific command that returns only, so some of the files didn’t run and some specific commands doesn’t add to path,

# /etc/bash.bashrc
# System-wide .bashrc file for interactive bash(1) shells.

# To enable the settings / commands in this file for login shells as well,
# this file has to be sourced in /etc/profile.

# If not running interactively, don't do anything
[ -z "$PS1" ] && return`

just comment out the line that returns early and everything should work fine, or you can use the real paths of the commands that you would like to use.

Thanks @kocyigityunus. Commenting the .bashrc line solved my issue. As my workflow runs nvm, yarn and docker scripts, that was the easiest way to handle

Along the same lines, does anyone have a solution for cd not working? thanks

Another approach is to put your command into the shell script file and execute sh xxxx.sh.

I will update the README to address the @kocyigityunus solution.

The full path didn’t work for me, but I found a solution. I realized that if I run echo $PATH in in a normal SSH session, I get a longer $PATH compared to what I get if I run the same command with the this GH Action workflow.

Reason: interactive vs non-interactive shell see → https://github.com/appleboy/ssh-action/issues/31#issuecomment-1006565847

basically, if you are running a command in a non interactive shell, like ssh-action, on many linux distros, “/etc/bash.bashrc” file has a specific command that returns only, so some of the files didn’t run and some specific commands doesn’t add to path,

Solution for npm: https://github.com/appleboy/ssh-action/issues/21#issuecomment-574050424

script: |
  export NVM_DIR=~/.nvm
  source ~/.nvm/nvm.sh
  npm --help

General solution:

  1. Run the action like so to see what is on the $PATH when the action runs
script: |
  echo $PATH
  1. A soft link inside one of the $PATH directories to the thing you are trying to use will probably solve the issue.

@ShravaniRoy @jgilm Were you able to overcome the issue? I am too facing a similar problem where I am not able to run multiple commands on the windows server

Hey Magesh, We actually moved to the ubuntu server. This worked fine on Ubuntu.

Only the first command works from script:

image

Am I missing something?? @appleboy – thank you!!

I’m having the same issue. SSH to Windows Server only runs a single comand @ShravaniRoy did you ever solve this?

Only the first command works from script:

image

Am I missing something?? @appleboy – thank you!!

you need to have the steps keyword @mittalyashu

I think it will try to execute inside the vps you’re trying to ssh into. You could use run instead like this

- name: Executing remote command
        uses: appleboy/ssh-action@v0.1.2
        run: sh ../../scripts/deploy.sh
        with:
          host: ${{ secrets.hosts }}
          USERNAME: ${{ secrets.USERNAME }}
          PORT: ${{ secrets.PORT }}
          KEY: ${{ secrets.SSHKEY }}

I think that should work