SSH pm2: command not found - ssh

When I run this command from my local machine...
ssh user#123.456.789.255 "pm2 reload all"
I get this error...
pm2: command not found
Running the command in the remote machine works fine, so it's not a pathing issue?

you need to run the nvm to get it going first
ssh user#123.456.789.255 "source ~/.nvm/nvm.sh && pm2 reload all"

Related

GitCI ssh to server returns bash: go: command not found

I have Go installed on my server. When I login through CLI I can successfully execute the "go build" and other commands.
Except when I SSH from my GitlabCI. I get this error:
bash: go: command not found
The code I am using currently:
ssh root#111.111.111.111"export PATH=$PATH:/root/.go/bin/go && cd /var/www/mysite.com/api && go build && exit"
As said, when I do it manually on my server it works perfectly, it just wont work when I do it through GitlabCI and I cannont figure out why.
I installed Go on my (Ubunto 18.04) server by using the guide here: https://golang.org/doc/install
Hope someone can help me out.
As NRE said, either a Symlink or "/root/.go/bin/go" would do the job and it sure did. Finally got it working now!

VSCode Remote-SSH Cannot Connect

I'm trying to use the Remote-SSH extension to edit files on a Linux server from my Windows 10 development machine. Normally, I log into the server using VNC and edit files locally OR I use WinSCP to pull the files to my development machine and copy them back over when done. The Remote-SSH extension seems to be the answer to this inefficiency.
I can SSH just fine using Putty or using Git Bash, but Remote-SSH fails to connect. There's some hints in the error message, but I'm not sure how to interpret them.
Here is my SSH config file (redacted) and the error I receive (redacted):
Config:
Host xxx.yy.gov
HostName xxx.yy.gov
User myusername
Error Message:
[08:44:36.981] remote-ssh#0.47.2
[08:44:36.981] win32 x64
[08:44:36.983] SSH Resolver called for "ssh-remote+xxx.yy.gov", attempt 1
[08:44:36.983] SSH Resolver called for host: xxx.yy.gov
[08:44:36.983] Setting up SSH remote "xxx.yy.gov"
[08:44:37.030] Using commit id "[some-string-of-numbers]" and quality "stable" for server
[08:44:37.033] Testing ssh with ssh -V
[08:44:37.101] ssh exited with code: 0
[08:44:37.101] Got stderr from ssh: OpenSSH_for_Windows_7.6p1, LibreSSL 2.6.4
[08:44:37.105] Running script with connection command: ssh -T -D 52772 xxx.yy.gov bash
[08:44:37.107] Install and start server if needed
[08:44:37.111] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[08:44:37.264] >
[08:44:37.264] Got some output, clearing connection timeout
[08:44:37.611] > myusername#xxx.yy.gov's password:
[08:44:37.612] Showing password prompt
[08:44:44.709] Got password response
[08:44:44.709] "install" wrote data to terminal: "**************"
[08:44:44.730] >
>
[08:44:45.102] > bash: bash: command not found
>
[08:44:45.476] "install" terminal command done
[08:44:45.476] Install terminal quit with output: bash: bash: command not found
[08:44:45.476] Received install output: bash: bash: command not found
[08:44:45.477] Stopped parsing output early. Remaining text: bash: bash: command not found
[08:44:45.477] Failed to parse remote port from server output
[08:44:45.477] Resolver error:
[08:44:45.480] TELEMETRY: {"eventName":"resolver","properties":{"outcome":"failure","reason":"UnparsableOutput",
"askedPw":"1","askedPassphrase":"0","asked2fa":"0","askedHostKey":"0","gotUnrecognizedPrompt":"0",
"remoteInConfigFile":"1"},"measures":{"resolveAttempts":1,"retries":1}}
[08:44:45.482] ------
VSCode Remote-SSH error
There are there are three ways you can try. I know the problem is annoying.
Check your vscode is local window or remote window. Then, check
remote-ssh setting. (Make sure Local Server Download is auto && Use
local Server is marked.).
Remote SSH:Path . you can switch to local ssh or git/ssh
Try to update or revert remote-ssh.(Version 0.50 can connect to server host stably, I found. This one is very useful.
Maybe you just select 'Linux' instead of 'Windows' though you are using Windows when you got the option to select Linux, Windows or Mac.
Since you are connecting to a server and not your own computer, the type of server you are connecting to is most likely Linux.

how to run pm2 in spawn process remotely from another server, not a shell script problem

this is not a problem related to shell script , this a problem on how to restart or use pm2 commands from spawn process in nodejs from a remote server. running the pm2 commands solo or in a shell script directly on the server , it works fine , but when i use spawn i get the error below.
how to restart pm2, using spawn process , using ssh root#ip
i've tried this
ssh root#ip 'pm2 restart all'
but when i try this on my local pc directly from my terminal
it works , but when i try to run it in exces or spawn process , i get this error bash: pm2: command not found failed with code 127
i also tried , putting my commands in script.sh
and send it with this command from spawn
scp /root/script.sh root#${ip}:/root&&ssh root#${ip} bash script.sh
i get the same error. but if i run alone in terminal it works , is the error in environment variable , it's not loaded correctly when i run it in spawn prcess.
ssh -t root#ip "export PATH='path/to/pm2'; pm2 restart all"
You should include the pathname to pm2 even if it is the current directory (eg ./pm2 or /path/to/pm2) to ensure it is found, or else export PATH=.... before the call to pm2.

ssh execute command remotely that not exist locally

Something like
ssh root#host "ls -l"
works fine
But when I'm trying
ssh root#host "showrgst"
I'm getting "command not found". And yes, I don't have showrgst command on the host I'm connected from.
How to solve this?
you need to install showrgst in the remote server and make sure the PATH env variable has the path to showrgst.
firstly, you can locate what executable is for this command
$ which showrgst
for example, it is executable script from $HOME/bin/showrgst.
So, you need to copy this file to server by means of scp -
$ scp ~/bin/showrgst youserver.com:/home/username/bin/
if this command is executable of some package existing in repositories linux disto, you can install this on your server

xvfb-run hanging on server

On our build server (bamboo launched) we are wanting to do selenium tests, to do this we are running xvfb-run, this works on our local servers which are all of the same type.
If I log on to the build server and run:
xvfb-run echo 'i'
I get the error:
xvfb-run: error: Xvfb failed to start
I have tried running like this:
xvfb-run -a echo 'i'
This time it just hangs and never finishes, any ideas on things I can try?
Thanks
Run following commands:
sudo nohup Xvfb :40 -ac &
export DISPLAY=:40
Since it works locally, I suspect a server or permissions issue is going on. Perhaps your user can't open up a lock file in /tmp ? Try to get more info about the problem by running:
xvfb-run -e /dev/stdout [mycommand]