如何在Lua脚本中建立ssh连接以在远程服务器上执行命令? [英] How to establish an ssh connection in a Lua script to execute a command on a remote server?

查看:517
本文介绍了如何在Lua脚本中建立ssh连接以在远程服务器上执行命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Lua中编写一个脚本,用于建立ssh连接以在远程服务器上执行命令

I want to write a script in Lua for establishing an ssh connection to execute a command on a remote server

谁能给我一个提示

谢谢

推荐答案

您可以使用os.execute ('ssh user@127.0.0.1')建立连接,但是您可能必须使用os.execute ('ssh user@127.0.0.1 &'..yourCommand)使其随后在外壳中执行,但是我不能完全确定它会起作用.最好在Bash中创建脚本并从Lua执行该脚本.如果需要运行不同的命令,则可以让脚本接收参数.

You can use os.execute ('ssh user@127.0.0.1') to make the connection, but you may have to use os.execute ('ssh user@127.0.0.1 &'..yourCommand) to make it execute afterwards in the shell, but I'm not entirely certain that it would work. It maybe better to create the script in Bash and execute that from Lua. If you needed to run differing commands, then you could have the script receive arguments.

这篇关于如何在Lua脚本中建立ssh连接以在远程服务器上执行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆