Skip to content

Some commands don't work #31

Closed
Closed

Description

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

Activity

  1. appleboy commented on Apr 30, 2020

    @appleboy
    Owner

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

  2. added
    bugSomething isn't working
    questionFurther information is requested
    on Apr 30, 2020
  3. palashCItobuz commented on May 7, 2020

    @palashCItobuz

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

  4. mittalyashu commented on Jul 7, 2020

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

  5. mojo706 commented on Jul 7, 2020

    @mojo706

    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

  6. mittalyashu commented on Jul 8, 2020

    @mittalyashu
    Contributor

    @mojo706 It shows an error:

    a step cannot have both the `uses` and `run` keys
    
  7. mojo706 commented on Jul 8, 2020

    @mojo706

    @mittalyashu could you show me your whole discord job?

  8. mittalyashu commented on Jul 8, 2020

    @mittalyashu
    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
  9. mojo706 commented on Jul 8, 2020

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

  10. mittalyashu commented on Jul 8, 2020

    @mittalyashu
    Contributor

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

    #31 (comment)

  11. mojo706 commented on Jul 8, 2020

    @mojo706

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

  12. mittalyashu commented on Jul 9, 2020

    @mittalyashu
    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
  13. appleboy commented on Jul 9, 2020

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

    @mojo706

    you need to have the steps keyword @mittalyashu

  15. 13 remaining items

  16. MageshSrinivasulu commented on Oct 10, 2022

    @MageshSrinivasulu

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

  17. mkosir commented on Oct 20, 2022

    @mkosir

    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 
  18. marqueetest commented on Jul 12, 2023

    @marqueetest

    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
    
  19. Jkarage commented on Jul 21, 2023

    @Jkarage

    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.

  20. MarcellHarmaci commented on Sep 5, 2023

    @MarcellHarmaci

    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.
  21. ondanieldev commented on May 4, 2024

    @ondanieldev

    @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

  22. appleboy commented on May 4, 2024

    @appleboy
    Owner

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

  23. appleboy commented on May 4, 2024

    @appleboy
    Owner
  24. quilicicf commented on Jul 12, 2024

    @quilicicf

    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
  25. dingshaohuax commented on Oct 13, 2024

    @dingshaohuax

    /etc/bash.bashrc

    no file /etc/bash.bashrc in centos9

  26. ondanieldev commented on Oct 13, 2024

    @ondanieldev

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

  27. dingshaohuax commented on Oct 13, 2024

    @dingshaohuax

    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

  28. cuikaipeng commented on Dec 23, 2024

    @cuikaipeng

    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

    thanks!!!
    it works for me

  29. izlatkin commented on Jul 3, 2025

    @izlatkin

    How to handle this scenario? I can't find a way to ignore the results of the kill
    - name: Stop previous version on AWS EC2
    uses: appleboy/ssh-action@v1
    with:
    host: ${{ secrets.AWS_HOST }}
    username: ${{ secrets.AWS_USERNAME }}
    key: ${{ secrets.AWS_SSH_KEY }}
    script: pkill -f "genart" || true

    ======= CLI Version =======
    Drone SSH version 1.8.1

    2025/07/03 03:04:24 Process exited with status 143 from signal TERM
    Error: Process completed with exit code 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingquestionFurther information is requested

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions