Generalize automatic login example for Linux

This commit is contained in:
Martin Lund 2024-04-19 14:44:54 +02:00
parent 29546bb13a
commit 96fafc5fb4

View file

@ -0,0 +1,29 @@
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
print("\r\nDon't know login info for " .. hostname .. "\r\n")
end
else
print("\r\nDidn't find a login prompt\r\n")
end