简体   繁体   English

我可以从节点 cli 应用程序切换到 bash 吗?

[英]Can I hand off from a node cli app to bash?

I'm working on a fairly simple node cli application for my agency that allows you to add clients and any of their sites to a db (lowdb) and then basically run the script with the client name to hand you off to an ssh session on their server.我正在为我的代理机构开发一个相当简单的节点 cli 应用程序,它允许您将客户端及其任何站点添加到数据库(lowdb),然后基本上使用客户端名称运行脚本,将您交给 ssh session他们的服务器。 I've tried the exec module, but it's just showing the password or key password prompt from ssh and not allowing me to actually continue with the session.我已经尝试过exec模块,但它只是显示来自 ssh 的密码或密钥密码提示,并且不允许我实际继续使用 session。

I'm wondering if there is a clean way to basically execute that initial ssh command but then just be running that on bash and not through the node app?我想知道是否有一种干净的方法可以基本上执行初始ssh命令,然后只是在 bash 上运行它而不是通过节点应用程序?

For example: If I use the following code...例如:如果我使用以下代码...

exec('ssh [options we always need] client@clientserver.com');

I get the following...我得到以下...

$ client's password: []

But it's just printing the stdout, not allowing me to continue with the session.但它只是打印标准输出,不允许我继续使用 session。 I just want the node cli to effectively end after starting the bash command running, allowing the user to login and continue as usual.我只希望节点 cli 在启动 bash 命令运行后有效结束,允许用户像往常一样登录并继续。

Why not just use a dedicated library instead of the command-line interface?为什么不直接使用专用库而不是命令行界面? Simply, implement the API and get the console input for the 'password', and then just pipe all command-line input to the SSH stream. Simply, implement the API and get the console input for the 'password', and then just pipe all command-line input to the SSH stream.

With node-ssh-forward , you simply establish a connection with the server using the input from the CLI and use the sshConnection.executeCommand('') command with the input from the user.使用node-ssh-forward ,您只需使用来自 CLI 的输入建立与服务器的连接,并使用来自用户的输入的sshConnection.executeCommand('')命令。 This library also supports callbacks so you can just console.log the results from the callback.该库还支持回调,因此您只需 console.log 回调的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从节点应用程序启动交互式bash脚本? - How can I start an interactive bash script from a node app? 将工作从PHP传递到Node.js是否可以接受(刮取图像)? - Is it acceptable to hand off a job ( scraping images ) to Node.js from PHP? 如何使用 cron 从 bash 运行节点脚本 - How can I run a node script from bash using cron 打包节点bash CLI以从/ usr / local / bin /文件夹执行 - Packing a node bash CLI for execution from the /usr/local/bin/ folder 我怎样才能运行 node cli with./index - How can i run node cli with ./index 如何调试通过命令行(cli)启动的节点应用程序,例如forever或supervisor? - how can I debug a node app that is started via the command line (cli) like forever or supervisor? 使用node.js:我可以创建一个仅显示日期和时间的CLI应用程序吗? - Playing with node.js: can I create a CLI app that simply displays the date and time? 如何将Polymer cli v-2.0与Node js一起使用并表达制作应用程序的权限? - how can I use polymer cli v-2.0 with node js and express for making app? 如何在节点和Express App中使用来自Polymer CLI的Polymer Starter Kit? - How do I use polymer starter kit from polymer cli in a node and express app? Jenkins离线节点CLI的麻烦 - Jenkins off-line node CLI troubles
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM