I’m working on an npm script intended to run an SSH command directly from the terminal. Currently, my approach involves using an osascript
to trigger Terminal to execute the command. However, I’m looking to modify this so that the command runs in the active terminal instead. I have both shelljs
and executive
in my script. When attempting to use executive
, it exits without any actions. On the other hand, using shelljs
leads to the error message:
Pseudo-terminal will not be allocated because stdin is not a terminal.
the input device is not a TTY
The command I’m trying to execute is: ssh -i [ssh-key] -t ubuntu@[ip-address] eval $(base64 -D <<< [encoded command])
, where the original command is sudo docker exec -i -t $(sudo docker ps -aqf “ancestor=’ + containerName + '”) /bin/bash
. When manually copying and pasting the command, it functions correctly, allowing me to SSH into a remote server and run a docker exec
operation.
If I omit the -t
flag, the warnings cease, but there’s no output in the console, leaving the script hanging. Conversely, if I exclude the eval …
part, I receive output resembling an SSH session but with no interactive terminal.
How can I run this SSH command interactively within the same terminal or in a new tab? If using an osascript
is necessary, I am open to that. Note that I will be executing the command from the terminal in PhpStorm.
Code Block:
const dockerCommand = 'sudo docker exec -i -t $(sudo docker ps -aqf "ancestor=nginx") /bin/bash';
const encodedCommand = Buffer.from(dockerCommand).toString('base64');
const sshCommand = `ssh -i ${this.keyPath} -t ubuntu@${ip} eval $(base64 -D <<< ${encodedCommand})`;
shell.exec(sshCommand);
Update:
I can now successfully SSH into the server, but I encounter a the input device is not a TTY
error upon adding the eval
command.
const dockerExecCommand = 'sudo docker exec -it $(sudo docker ps -aqf "ancestor=' + containerName + '") /bin/bash';
const encodedDockerExec = Buffer.from(dockerExecCommand).toString('base64');
const sshProcess = spawn('ssh', [
'-i',
this.keyPath,
'ubuntu@' + ip,
'eval',
'eval $(base64 -D < {
process.exit(0);
});