javascript - 使用 href ssh ://url with command line options 从 html 打开终端

标签 javascript html url ssh terminal

我想创建一个 url 链接来启动终端(从网页或浏览器,如 chrome 或 safari)和 ssh 到一个盒子并启动远程命令(例如 ls ),在终端中它看起来像: ssh user@1.2.3.4 'ls'

我试过:

<a href='ssh://user@1.2.3.4 "ls"'>SSH with ls</a>

但这没有任何作用。 这有效(没有任何命令):

<a href='ssh://user@1.2.3.4'>SSH</a>

这在 HTML 中可能吗?我也会接受使用 Javascript 的答案。

最佳答案

我查看了多个来源并尝试了不同的组合并得出以下理解

  • 没有为 SSH URI 定义的标准来指定命令。因此,要了解如何使用输入取决于接受输入的过程
  • 默认情况下 Terminal.app 处理 SSH url 并且没有文档表明它支持命令
  • 接收 URL 的应用程序没有将 URL 作为参数获取,它需要使用某些事件来获取它。可以引用here同样
  • 您可以配置 iTerm 来处理 SSH 处理程序并访问按描述 here 传递的 URL
  • 您可以创建一个自定义应用来处理 URL 并支持命令和其他您想要的东西

使用 iTerm 实现

您创建一个新配置文件并在同一配置文件中启用 SSH URL 处理程序

SSH handling

因此在示例页面下方使用

<html>
<body>
<a href="ssh://vagrant@vm/ls -alh">ls -alh</a>
</body>
</html>

在我的 iTerm SSH 配置文件中执行以下命令

/usr/bin/ssh $$USER$$@$$HOST$$  $(echo $$PATH$$ | tr -d '/')

结果是

Result

当然,您想运行 python 脚本或其他东西并将这些值传递给它,并让它为附加功能做这些事情。但这显示了如何实现这样的设置

主要引用资料

url scheme for ssh: Calling command on remote host

https://unix.stackexchange.com/questions/75668/why-doesnt-the-ssh-command-follow-rfc-on-uri

https://groups.google.com/forum/#!topic/iterm2-discuss/r0Rk_WZaGWk

http://www.rubicode.com/Software/Bundles.html#RCDefaultApp

https://superuser.com/questions/379342/setting-iterm2-as-the-default-terminal-osx-lion

https://apple.stackexchange.com/questions/46666/how-to-access-a-clicked-url-in-a-url-handler-application-created-in-automator

https://support.shotgunsoftware.com/hc/en-us/community/posts/209485898-Launching-External-Applications-using-Custom-Protocols-under-OSX

关于javascript - 使用 href ssh ://url with command line options 从 html 打开终端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49036515/

相关文章:

html - CSS3 框阴影问题

url - 当 URL 中提供凭据时,为什么浏览器不发送 Authentication header ?

Javascript 和 W3C 有效性?

带有随机变量的Javascript if else语句

javascript - 使用jquery隐藏iframe

ruby-on-rails - 您将如何解析 Ruby 中的 url 以获取主域?

javascript - jQuery 不工作,但 document.querySelector 可以 (CasperJS)

javascript - InnerHTML 同时提醒它在 firefox 中用双引号提醒,但在 IE 中不提醒

javascript - jQuery CLNDR : add div within date block