Issue
When I run
gcloud compute ssh user@instance-1
And then when I am ssh'd in, I type pm2
and it prints out a help message, as expected.
If I instead run
gcloud compute ssh user@instance-1 --command "pm2"
It prints out bash: pm2: command not found
I had previously installed pm2
(by running npm install -g pm2
as both the root user and user
for good measure).
What is going on here?
Solution
My assumption is that in the first recipe, you perform a login meaning that your .profile and/or .bashrc scripts are run which modify your PATH environment variable to include the location of the command you wish to run (pm2
). In the second recipe, where you supply --command
my assumption is that the executable is being forked/execed (run directly) without your profile scripts being executed. This results in the command not found. Maybe try and run a script (through command) that logs your environment variables (for example /bin/env
) and see how they differ from what you find when you are actually logged in.
Another solution would be to supply the full path to pm2
in your command.
Answered By - Kolban