tio/examples/lua/automatic-linux-login.lua
Martin Lund 6e779a0520 Use lua io.write() instead of print()
io.write() gives better output control as print() is hardcoded to always
print a newline.
2024-04-27 00:48:38 +02:00

29 lines
709 B
Lua

local logins = {
["foo"] = {
username = "foouser",
password = "foopass",
},
["bar"] = {
username = "baruser",
password = "barpass",
},
["baz"] = {
username = "bazuser",
password = "bazpass",
},
}
local found, match_str = expect("\\w+- login:", 10)
if (1 == found) then
local hostname = string.match(match_str, "^%w+")
local login = logins[hostname]
if (nil ~= login) then
send(login.username .. "\n")
expect("Password:")
send(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