-1

I'm using the following library to do: http://maboiteaspam.github.io/ssh2-utils/

  1. Login to altus instance
  2. Go to a directory.

This is my code:

function postRun(url){
        ssh.runMultiple(server, "sudo docker exec -it abcas /bin/bash", function(err,stdout,stderr,server,conn){
            if(err) console.log(err);
            stdout.on('data', function(data){
                executeCommands();

            });
            stderr.on('data', function(data){
                console.log(''+data);
            });
            stdout.on('close',function(data){
                conn.end();
            });
        });
}

function executeCommands(){
        ssh.runMultiple(server, ['cd /dependencies/scripts'], function(err,stdout,stderr,server,conn){
            if(err) console.log(err);
            stdout.on('data', function(data){
                ssh.exec(server, 'pwd', function(err,stdout,stderr){
                    if(err) console.log(err);
                });
            });
            stderr.on('data', function(data){
                console.log(''+data);
            });
            stdout.on('close',function(data){
                conn.end();
            });
        });
}

I get the following error:

bash: line 0: cd: /dependencies/scripts: No such file or directory

I am not sure what I'm doing wrong. I read somewhere that I need to change my shell but looks like I'm in bash already.

What am I missing, please enlighten.

TechnoCorner
  • 4,879
  • 10
  • 43
  • 81
  • You are trying to enter a non existent directory. Don't blame SSH or Node over this... The error message tells you that the SSH command execution itself did work but the outcome was non successful (i.e. non-zero return code). Verify that the path /dependencies/scripts exists. – marekful Sep 28 '17 at 05:56
  • The error is from bash, not from ssh. See if you can cd /dependencies/scripts from the command line. – Krassi Em Sep 28 '17 at 06:01
  • The thing is.. the directory is present and I can cd into the directory. @marekful that's what annoys me :-( I spent hours trying to figure out what's happening and I gave up :-( – TechnoCorner Sep 28 '17 at 17:31
  • I see what you mean.. So the thing is, the directory DOES exist. But when i do `postRun()` from another linux box .. it's supposed to go `"Inside"` a docker instance and then do `"cd"` but it does `cd` from outside box. (Not inside docker) .. Not really sure how i should be fixing this.. Should i be using `ssh.runMultiple?` – TechnoCorner Sep 28 '17 at 18:27
  • A common beginner error is not understanding the significance of the slash. Does the directory `/dependencies` really exist in the root directory? Or do you hope to find a directory `dependencies` in your home directory (notice absence of leading slash)? – tripleee Dec 21 '18 at 06:05
  • I don't really understand the reasoning behind -1 rating. I made my own attempts and gave a right question with my genuine attempts. – TechnoCorner Dec 21 '18 at 06:12

1 Answers1

0

The "cd /" - Indicates it goes to root, so you have to specify the full path to go to the directory starting from the parent directory from root.

venkat
  • 442
  • 5
  • 17