ssh-action icon indicating copy to clipboard operation
ssh-action copied to clipboard

Some commands don't work

Open ClassyCircuit opened this issue 5 years ago • 31 comments
trafficstars

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.

ClassyCircuit avatar Feb 09 '20 17:02 ClassyCircuit

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

appleboy avatar Apr 30 '20 08:04 appleboy

@appleboy

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

The shell script is being able to run node js or npm commands. How can they be executed? Tried loading . /etc/profile in the shell script.

palashCItobuz avatar May 07 '20 15:05 palashCItobuz

Any suggestions?

      - name: Executing remote command
        uses: appleboy/[email protected]
        with:
          host: ${{ secrets.hosts }}
          USERNAME: ${{ secrets.USERNAME }}
          PORT: ${{ secrets.PORT }}
          KEY: ${{ secrets.SSHKEY }}
          script: sh ../../scripts/deploy.sh

If we try to execute sh ../../scripts/deploy.sh wouldn't it will try running inside the server where we're trying SSH into.

mittalyashu avatar Jul 07 '20 11:07 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/[email protected]
        run: sh ../../scripts/deploy.sh
        with:
          host: ${{ secrets.hosts }}
          USERNAME: ${{ secrets.USERNAME }}
          PORT: ${{ secrets.PORT }}
          KEY: ${{ secrets.SSHKEY }}

I think that should work

mojo706 avatar Jul 07 '20 18:07 mojo706

@mojo706 It shows an error:

a step cannot have both the `uses` and `run` keys

mittalyashu avatar Jul 08 '20 03:07 mittalyashu

@mittalyashu could you show me your whole discord job?

mojo706 avatar Jul 08 '20 04:07 mojo706

@mojo706

- name: Executing remote command
  uses: appleboy/[email protected]
  env:
    BACKEND_APP_PORT: 8080
    NODE_ENV: "production"
  with:
    host: ${{ secrets.IP }}
    USERNAME: ${{ secrets.USERNAME }}
    PORT: ${{ secrets.PORT }}
    KEY: ${{ secrets.SSHKEY }}
    envs: BACKEND_APP_PORT, NODE_ENV
    script: ls

mittalyashu avatar Jul 08 '20 04:07 mittalyashu

  steps:
    - name: Executing remote command
      uses: appleboy/[email protected]
      env:
        BACKEND_APP_PORT: 8080
        NODE_ENV: "production"
      with:
        host: ${{ secrets.IP }}
        USERNAME: ${{ secrets.USERNAME }}
        PORT: ${{ secrets.PORT }}
        KEY: ${{ secrets.SSHKEY }}
        envs: BACKEND_APP_PORT, NODE_ENV
        script: ls

@mittalyashu try that

mojo706 avatar Jul 08 '20 04:07 mojo706

Isn't it the exact same code which I have shared.

https://github.com/appleboy/ssh-action/issues/31#issuecomment-655275661

mittalyashu avatar Jul 08 '20 06:07 mittalyashu

Lol shit I forgot to change it. I guess I was tired, I wanted you to add run under uses it should work now.

mojo706 avatar Jul 08 '20 15:07 mojo706

You mean something like this?

- name: Executing remote command
  uses: appleboy/[email protected]
  run: echo "Running this in GitHub Action"
  env:
    BACKEND_APP_PORT: 8080
    NODE_ENV: "production"
  with:
    host: ${{ secrets.IP }}
    USERNAME: ${{ secrets.USERNAME }}
    PORT: ${{ secrets.PORT }}
    KEY: ${{ secrets.SSHKEY }}
    envs: BACKEND_APP_PORT, NODE_ENV
    script: ls

mittalyashu avatar Jul 09 '20 01:07 mittalyashu

  with:
    host: ${{ secrets.IP }}
    username: ${{ secrets.USERNAME }}
    port: ${{ secrets.PORT }}
    key: ${{ secrets.SSHKEY }}
    envs: BACKEND_APP_PORT, NODE_ENV
    script: ls

appleboy avatar Jul 09 '20 01:07 appleboy

you need to have the steps keyword @mittalyashu

mojo706 avatar Jul 09 '20 02:07 mojo706

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

bnbrndn avatar Jan 02 '21 20:01 bnbrndn

@bnbrndn Post your config.

appleboy avatar Jan 03 '21 01:01 appleboy

I had some problem when i use root user access

nick339s avatar Feb 01 '21 13:02 nick339s

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

Did you find a solution @bnbrndn

ShravaniRoy avatar Feb 22 '21 19:02 ShravaniRoy

Only the first command works from script:

image

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

ShravaniRoy avatar Feb 22 '21 19:02 ShravaniRoy

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

Did you find a solution @bnbrndn

The problem I was having was I needed to CD into a directory to run composer install. The work around I found was to run "composer install -d public_html"

Not the cleanest, but it did what I needed

bnbrndn avatar Feb 22 '21 21:02 bnbrndn

第一次同步时安装git, 第二次就可以把 yum -y install git 去掉了

suxiaolong avatar Jul 28 '21 08:07 suxiaolong

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?

jgilm avatar Oct 19 '21 18:10 jgilm

This is crazy! the issue is yet not solved! I tried all different commands to run my sh file on remote local But it's not working, I guess it's running on a virtual docker environment. How could I run this on my remote machine?

@appleboy Please can you help.

MahbbRah avatar Nov 23 '21 04:11 MahbbRah

@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.

kocyigityunus avatar Jan 06 '22 12:01 kocyigityunus

Thanks @kocyigityunus. The hint for using the real paths

or you can use the real paths of the commands that you would like to use.

works for me

ronatory avatar Feb 07 '22 21:02 ronatory

@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

MageshSrinivasulu avatar Oct 10 '22 05:10 MageshSrinivasulu

@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.

ShravaniRoy avatar Oct 10 '22 05:10 ShravaniRoy

@ShravaniRoy Thanks for the quick response. Created a separate issue for the same https://github.com/appleboy/ssh-action/issues/189

MageshSrinivasulu avatar Oct 10 '22 06:10 MageshSrinivasulu

Hey, went through the answers and tried different approaches but nothing worked. My question is how it would be possible to run my shell/bash script in separate file (my-script.sh), which is located on ext to github action file CI.yml?

 - name: Executing remote command
        uses: appleboy/[email protected]
        with:
          ...
          script: sh ./my-script.sh

In other CIs or terminal where this nice appleboy/ssh-action doesnt exist, to make it work you pass your own shell script as:

ssh root@${server} 'bash -s' < ./my-script.sh 

mkosir avatar Oct 20 '22 11:10 mkosir

Here is my config

      - name: Deploy source-code
        uses: appleboy/ssh-action@master
        with:
          HOST: ${{ secrets.HOST }}
          USERNAME: ${{ secrets.USER }}
          PORT: ${{ secrets.PORRT }}
          PASSWORD: ${{ secrets.PASSWORD }}
          script: |
            sh /var/www/automation/rerun-project.sh

Below is my sh file

cd /var/www/html/my-project
git pull
npm install
forever restart project

But while action run on git hub, it is giving below error

err: /var/www/automation/rerun-project.sh: 3: /var/www/automation/rerun-project.sh: npm: not found
err: /var/www/automation/rerun-project.sh: 4: /var/www/automation/rerun-project.sh: forever: not found

Below first two command working perfectly fine but not sure why npm and forever not working. npm & forever command I am able to execute from putty.

cd /var/www/html/my-project
git pull

marqueetest avatar Jul 12 '23 09:07 marqueetest

Using the full path of the binary in the script worked for me. I believe the non interactive shell obtained from appleboy does not load the correct profiles.

// Example /usr/local/go/bin/go build -o ./bin/client /usr/bin/npm install

Hope using this or other tools would work.

Jkarage avatar Jul 21 '23 12:07 Jkarage