5

Up until recently, it has worked fine, but when I tried to use it today, it did not work properly. It returns the following error:

Error: Command failed: /bin/sh -c /home/pi/RPi-Computer-Power/RPi-Server/routes/../scripts/hash.js 12345678 /bin/sh: 1: /home/pi/RPi-Computer-Power/RPi-Server/routes/../scripts/hash.js: Permission denied

I am extremely confused because when I try to run the script from the command line, it works perfectly; /home/pi/RPi-Computer-Power/RPi-Server/routes/../scripts/hash.js 12345 executes flawlessly.

This is the code where I try to execute the script. (index.js)

exec(__dirname+"/../scripts/"+req.params.script+" "+req.body.params, function(err, stdout, stderr) {
        console.log("err: ",err,"stdout: ",stdout,"stderr: ",stderr);
        if(err){
          res.send("<a href='/'>< Back</a> <b>Program Error:</b> "+err.toString());
          return;
        }
        //res.send("<a href='/'>< Back</a> <b>Program Output:</b> <div style='white-space:pre-line>'"+stdout+stderr+"</div>");
        res.render("programOutput", {output: stdout});
      });

If anyone has any help, thank you in advance. Neil

1
  • How are you running node.js? What permissions does it have? Commented May 6, 2017 at 0:51

1 Answer 1

7

Two things come to mind:

1) Make sure that the script you are trying to execute is executable ex: chmod +x /folder/script

2) The default terminal shell on many Linux distributions is bash. The error you displayed includes using /bin/sh -c, which would default in many Linux distributions to dash (yes, a different default shell for the terminal and for running scripts without the terminal). Thus, since it seems to work in bash, try to evoke the script with bash -c /folder/script.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, thank you, the chmod +x * in the scripts directory method worked for me. I thought I tried to chmod 755 *, but I guess that wasn't what I needed to do. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.