-
Notifications
You must be signed in to change notification settings - Fork 4
/
remote.tcl
49 lines (38 loc) · 1.08 KB
/
remote.tcl
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
proc remote_sudocmd {username target ssh_port password cmds} {
spawn ssh -t -p $ssh_port $username@$target sudo -- bash -c '$cmds'
# for ssh password
expect "*password*"
send "$password\r"
# for sudo command
expect "*password*"
send "$password\r"
# wait for completion of ssh
expect eof
}
proc remote_sudocmd_registered {username target ssh_port password cmds} {
spawn ssh -t -p $ssh_port $username@$target sudo -- bash -c '$cmds'
# for sudo command
expect "*password*"
send "$password\r"
# wait for completion of ssh
expect eof
}
proc remote_sudoercmd {username target ssh_port password cmds} {
remote_cmd_n_password $username $target $ssh_port $password $cmds 1
}
# Do remote command which requires n-time password input
proc remote_cmd_n_password {username target ssh_port password cmds nr_prompt} {
spawn ssh -t -p $ssh_port $username@$target bash -c '$cmds'
# for ssh password
expect "*password*"
send "$password\r"
set i 0
while {$i < $nr_prompt} {
puts "$i prompt"
expect "*password*"
send "$password\r"
incr i
}
# wait for completion of ssh
expect eof
}