mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Lua API moved into a tio library table and names adjusted to Lua stdlib style. Regex in expect() replaced with Lua patterns so binary data can be handled. New tio.alwaysecho variable allows enabling and disabling echo to console. Read and write functions now manage complex retry and timeout logic internally, giving the user a simple "nil if fail" API like the rest of Lua. exit() was removed, os.exit() already exists in the Lua standard library.
28 lines
663 B
Lua
28 lines
663 B
Lua
local logins = {
|
|
["foo"] = {
|
|
username = "foouser",
|
|
password = "foopass",
|
|
},
|
|
["bar"] = {
|
|
username = "baruser",
|
|
password = "barpass",
|
|
},
|
|
["baz"] = {
|
|
username = "bazuser",
|
|
password = "bazpass",
|
|
},
|
|
}
|
|
|
|
local hostname = tio.expect("^(%g+) login:", 10)
|
|
if hostname then
|
|
local login = logins[hostname]
|
|
if (nil ~= login) then
|
|
tio.write(login.username .. "\n")
|
|
tio.expect("Password:")
|
|
tio.write(login.password .. "\n")
|
|
else
|
|
io.write("\r\nDon't know login info for " .. hostname .. "\r\n")
|
|
end
|
|
else
|
|
io.write("\r\nDidn't find a login prompt\r\n")
|
|
end
|