[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some commands don't work #31

Closed
ClassyCircuit opened this issue Feb 9, 2020 · 38 comments
Closed

Some commands don't work #31

ClassyCircuit opened this issue Feb 9, 2020 · 38 comments
Labels
bug Something isn't working question Further information is requested

Comments

@ClassyCircuit
Copy link
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.

@appleboy
Copy link
Owner

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

@appleboy appleboy added bug Something isn't working question Further information is requested labels Apr 30, 2020
@palashCItobuz
Copy link
palashCItobuz commented May 7, 2020

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

@mittalyashu
Copy link
Contributor

Any suggestions?

      - name: Executing remote command
        uses: appleboy/ssh-action@v0.1.2
        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.

@mojo706
Copy link
mojo706 commented Jul 7, 2020

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

@mittalyashu
Copy link
Contributor
mittalyashu commented Jul 8, 2020

@mojo706 It shows an error:

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

@mojo706
Copy link
mojo706 commented Jul 8, 2020

@mittalyashu could you show me your whole discord job?

@mittalyashu
Copy link
Contributor

@mojo706

- name: Executing remote command
  uses: appleboy/ssh-action@v0.1.2
  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

@mojo706
Copy link
mojo706 commented Jul 8, 2020
  steps:
    - name: Executing remote command
      uses: appleboy/ssh-action@v0.1.2
      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

@mittalyashu
Copy link
Contributor

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

#31 (comment)

@mojo706
Copy link
mojo706 commented Jul 8, 2020

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

@mittalyashu
Copy link
Contributor

You mean something like this?

- name: Executing remote command
  uses: appleboy/ssh-action@v0.1.2
  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

@appleboy
Copy link
Owner
appleboy commented Jul 9, 2020
  with:
    host: ${{ secrets.IP }}
    username: ${{ secrets.USERNAME }}
    port: ${{ secrets.PORT }}
    key: ${{ secrets.SSHKEY }}
    envs: BACKEND_APP_PORT, NODE_ENV
    script: ls

@mojo706
Copy link
mojo706 commented Jul 9, 2020

you need to have the steps keyword @mittalyashu

@bnbrndn
Copy link
bnbrndn commented Jan 2, 2021

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

@appleboy
Copy link
Owner
appleboy commented Jan 3, 2021

@bnbrndn Post your config.

@nick339s
Copy link
nick339s commented Feb 1, 2021

I had some problem when i use root user access

@ShravaniRoy
Copy link

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

Did you find a solution @bnbrndn

@ShravaniRoy
Copy link
ShravaniRoy commented Feb 22, 2021

Only the first command works from script:

image

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

@bnbrndn
Copy link
bnbrndn commented Feb 22, 2021

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

@suxiaolong
Copy link


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

@jgilm
Copy link
jgilm commented Oct 19, 2021

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?

@MahbbRah
Copy link

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.

@kocyigityunus
Copy link
kocyigityunus commented Jan 6, 2022

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

@ronatory
Copy link
ronatory commented Feb 7, 2022

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

@MageshSrinivasulu
Copy link

@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

@ShravaniRoy
Copy link

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

@MageshSrinivasulu
Copy link

@ShravaniRoy Thanks for the quick response. Created a separate issue for the same #189

@mkosir
Copy link
mkosir commented Oct 20, 2022

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/ssh-action@v0.1.2
        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 

@marqueetest
Copy link

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

@Jkarage
Copy link
Jkarage commented Jul 21, 2023

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.

@MarcellHarmaci
Copy link

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 → #31 (comment)

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: #21 (comment)

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.

@ondanieldev
Copy link
ondanieldev commented May 4, 2024

@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

@appleboy
Copy link
Owner
appleboy commented May 4, 2024

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

@appleboy
Copy link
Owner
appleboy commented May 4, 2024

See the document: https://github.com/appleboy/ssh-action#command-not-found-npm-or-other-command

@appleboy appleboy closed this as completed May 4, 2024
@quilicicf
Copy link

Another solution that works (only for node global modules):

script: |
  PATH="$PATH:$(npm get prefix)/bin" # Adds global node modules to the PATH
  pm2 list # Uses a global node module, now in the PATH

@dingshaohua-com
Copy link

/etc/bash.bashrc

no file /etc/bash.bashrc in centos9

@ondanieldev
Copy link

Currently I do not have issues with that, but I do not use bash on my servers anymore. Instead, I use zsh.

@dingshaohua-com
Copy link

I have found a good solution, just add a line to your script, eg:

script: |
     source /etc/profile
     java -version

the /etc/profile is working for ssh remote command user, refer to this article

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests