-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh-expect
40 lines (36 loc) · 828 Bytes
/
ssh-expect
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
#! /usr/bin/expect
if { $argc < 5 } {
send_user " ERROR : Invalid arguments.\n"
send_user " Usage : $argv0 host port user pw cmd\n"
exit 10
}
set host [ lindex $argv 0 ]
set port [ lindex $argv 1 ]
set user [ lindex $argv 2 ]
set pw [ lindex $argv 3 ]
set cmd [ lindex $argv 4 ]
set timemout 15
spawn ssh $user@$host -p $port $cmd
set ssh_id $spawn_id
expect {
-nocase "yes/no" {
exp_send "yes\r"
exp_continue
}
-nocase "password:" {
exp_send "${pw}\r"
expect "try again" {
send_user "\nERROR: Password is incorrect!\n"
close $spawn_id
exit 12
}
}
-nocase "powershell" {
exit 0
}
default {
send_error "ERROR : timeout or eof.\n"
close $spawn_id
exit 11
}
}