简体   繁体   中英

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)

Executing the below command, will run the shell file inside AWS server

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

     node test.js
  • test.js file [Node file]

     console.log("Venkatesh");

If I run the shell command directly inside the AWS server, node file runs perfectly. But if I run with the ssh command, it throws an error like this:

line 1: node: command not found

I have also tried from nodejs by using node-ssh package, same error occurs again.

How do I suppose to run a node file through shell script from ssh command?

Thanks to 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  #FULL/PATH/TO/NODE
FULL/PATH/TO/NODE test.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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