File: login.exp

package info (click to toggle)
sssd 2.10.1-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 62,640 kB
  • sloc: ansic: 320,236; xml: 81,740; python: 39,728; sh: 7,899; makefile: 6,509; exp: 67; cpp: 22; sed: 16
file content (72 lines) | stat: -rwxr-xr-x 1,264 bytes parent folder | download | duplicates (3)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/expect

set timeout 20
set user [lindex $argv 0]
set password [lindex $argv 1]
set principal [lindex $argv 2]

set distribution [exec "lsb_release" "-is"]

if { $distribution == "Ubuntu" } {
    set welcome "Welcome to"
} elseif { $distribution == "Debian" } {
    set welcome "Debian GNU/Linux comes"
} else {
    puts "Unsupported linux distribution $distribution"
    exit 1
}

spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $user@localhost
expect "assword: "
send "$password\r"
expect {
  timeout
  {
    puts "Expect error: timeout after password\r\r"
    exit 1
  }
  "Login incorrect"
  {
    puts "Expect error: incorrect credentials\r\r"
    exit 1
  }
  "$welcome"
}
expect {
  timeout
  {
    puts "Expect error: timeout waiting for prompt\r\r"
    exit 1
  }
  "$ "
}
send "id -un\r"
expect {
  timeout
  {
    puts "Expect error: timeout waiting for 'id' result\r\r"
    exit 1
  }
  "$user"
}
expect {
  timeout
  {
    puts "Expect error: timeout waiting for prompt\r\r"
    exit 1
  }
  "$ "
}
if { $principal != "" } {
  send "klist\r"
  expect {
    timeout
    {
      puts "Expect error: timeout waiting for klist output\r\r"
      exit 1
    }
    "Default principal: $principal"
  }
}
send "logout\r"
exit 0