user748765
user748765

Reputation: 21

How to establish an ssh connection in a Lua script to execute a command on a remote server?

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

Can anyone give me a hint

Thank you

Upvotes: 2

Views: 8942

Answers (3)

Alexander Gladysh
Alexander Gladysh

Reputation: 41393

The simplest solution is to use io.popen as others suggested. If you want more control, try lpty.

Upvotes: 0

Paŭlo Ebermann
Paŭlo Ebermann

Reputation: 74750

As said by U319344, os.execute would be enough if you simply want to execute some program at the remote side.

If you need to interact with this program, you will need io.popen - it returns a file handle which you can use to read from and write to the remote command.

(And usually you will want to setup public-key authentication to not have to deal with passwords here.)

Upvotes: 0

U319344
U319344

Reputation: 111

You can use os.execute ('ssh [email protected]') to make the connection, but you may have to use os.execute ('ssh [email protected] &'..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.

Upvotes: 1

Related Questions