简体   繁体   English

通过 shell 脚本从 ssh 命令运行节点文件

[英]Run node file from ssh command through shell script

Here I'm trying to run node file in AWS server with the ssh command through the shell script, where inside the shell file there is a command to run node file (node test.js)在这里,我尝试使用 ssh 命令通过 shell 脚本在 AWS 服务器中运行节点文件,其中在 shell 文件中有一个运行 test.js 文件的命令

Executing the below command, will run the shell file inside AWS server执行以下命令,将在 AWS 服务器中运行 shell 文件

ssh -i sample-test.pem ubuntu@ip 'bash -s' < my-folder/test.sh
  • test.sh file [Shell file] test.sh文件 [外壳文件]

     node test.js
  • test.js file [Node file] test.js文件 [节点文件]

     console.log("Venkatesh");

If I run the shell command directly inside the AWS server, node file runs perfectly.如果我直接在 AWS 服务器内运行 shell 命令,节点文件运行完美。 But if I run with the ssh command, it throws an error like this:但是,如果我使用 ssh 命令运行,它会引发如下错误:

line 1: node: command not found

I have also tried from nodejs by using node-ssh package, same error occurs again.我也尝试过使用node-ssh package 从 nodejs,同样的错误再次发生。

How do I suppose to run a node file through shell script from ssh command?如何通过 ssh 命令的 shell 脚本运行节点文件?

Thanks to ROOT感谢ROOT

Add the node path while running the node file.在运行节点文件时添加节点路径。 The response of which node will be add to run the node file.将添加which node的响应以运行节点文件。

which node  #FULL/PATH/TO/NODE
FULL/PATH/TO/NODE test.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM