title: Execute ssh shell script from npm command
body: <p>I'm trying to write an npm script that will execute an ssh shell command. Currently it's working by executing an <code>osascript</code> command to open a Terminal window and run the command. </p>
  
  <p>I'd like to change this to execute the command in the current terminal. The script is including both <code>shelljs</code> and <code>executive</code>. The script ends without anything happening when I use <code>executive</code>. With <code>shelljs</code> I get:</p>
  
  <p><code>Pseudo-terminal will not be allocated because stdin is not a terminal.
  the input device is not a TTY
  </code></p>
  
  <p>The command being executed is: <code>ssh -i [ssh-key] -t ubuntu@[ip-address] eval $(base64 -D &lt;&lt;&lt; [command in base64])</code></p>
  
  <p>The base64 command is <code>sudo docker exec -i -t $(sudo docker ps -aqf "ancestor=' + containerName + '") /bin/bash</code></p>
  
  <p>If I output the command and copy and paste it, it will work as expected, sshing into a remote machine and running a <code>docker exec</code> command.</p>
  
  <p>If I remove the <code>-t</code> option I don't get the warning messages but there's no output in the console and the script hangs (I assume it's running the command in the background with no output). If I remove the <code>eval ...</code> part I get an output that looks like what you'd see when sshing into a server but without the input terminal.</p>
  
  <p>What can I do to execute this command in the same terminal or in a new tab. If I have to use an <code>osascript</code> command to do this, that's fine as well. I'll be executing this command from the terminal in PhpStorm though.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Here's the block of code:</p>
  
  <pre><code>var execCommand = 'sudo docker exec -i -t $(sudo docker ps -aqf "ancestor=nginx") /bin/bash';
  
  var buffer = new Buffer(execCommand);
  var encoded = buffer.toString('base64');
  
  var cmd = "ssh -i " + this.keyPath + " -t ubuntu@" + ip + " eval $(base64 -D &lt;&lt;&lt; " + encoded + ") ";
  
  shell.exec(cmd);
  </code></pre>
  
  <p><strong>Edit 2</strong></p>
  
  <p>I can ssh into the machine successfully and get a command prompt but I'm getting a <code>the input device is not a TTY</code> error now when I add the <code>eval</code> command.</p>
  
  <pre><code>var docker_exec = 'sudo docker exec -it $(sudo docker ps -aqf "ancestor=' + containerName + '") /bin/bash';
  var encoded = new Buffer(docker_exec).toString('base64');
  
  var sshTerm = spawn('ssh', [
      '-i',
      this.keyPath,
      'ubuntu@' + ip,
      'eval',
      'eval $(base64 -D &lt;&lt;&lt; ' + encoded + ')'
  ], {
      stdio: 'inherit',
      shell: true
  });
  
  sshTerm.on('exit', function() {
      process.exit(0);
  });
  </code></pre>