ssh-action
ssh-action copied to clipboard
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.
Another approach is to put your command into the shell script file and execute sh xxxx.sh.
@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.
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.
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 It shows an error:
a step cannot have both the `uses` and `run` keys
@mittalyashu could you show me your whole discord job?
@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
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
Isn't it the exact same code which I have shared.
https://github.com/appleboy/ssh-action/issues/31#issuecomment-655275661
Lol shit I forgot to change it. I guess I was tired, I wanted you to add run under uses it should work now.
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
with:
host: ${{ secrets.IP }}
username: ${{ secrets.USERNAME }}
port: ${{ secrets.PORT }}
key: ${{ secrets.SSHKEY }}
envs: BACKEND_APP_PORT, NODE_ENV
script: ls
you need to have the steps keyword @mittalyashu
Along the same lines, does anyone have a solution for cd not working? thanks
@bnbrndn Post your config.
I had some problem when i use root user access
Along the same lines, does anyone have a solution for cd not working? thanks
Did you find a solution @bnbrndn
Only the first command works from script:

Am I missing something?? @appleboy -- thank you!!
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
第一次同步时安装git, 第二次就可以把 yum -y install git 去掉了
Only the first command works from script:
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?
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
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. 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
@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 @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 Thanks for the quick response. Created a separate issue for the same https://github.com/appleboy/ssh-action/issues/189
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
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
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.