File: automatic-linux-login.lua

package info (click to toggle)
tio 3.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,128 kB
  • sloc: ansic: 6,868; makefile: 3
file content (29 lines) | stat: -rw-r--r-- 711 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
        write(login.username .. "\n")
        expect("Password:")
        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