tcl
重要资料:
遇到过的问题:
-
shell - Read file into String and do a loop in Expect Script - Stack Overflow
-
remove file path and extension in Tcl command - Stack Overflow·
-
expect - Create a directory if it doesn’t exist in TCL - Unix & Linux Stack Exchange
-
try catch - try and ignore errors in my tcl command - Stack Overflow
bps中获取帮助的方法:
-
选项:-h, -help参数
-
子命令:输入任意错误的子命令
-
会被误以为是搜索关键字的子命令:未知
-
不输入任何参数
TCL的注意事项
- 很多时候大括号只是相当于双引号
expect
重要资料:
- 手册:man expect
遇到过的问题:
shell - replace space with underscore in expect script - Unix & Linux Stack Exchange
样例
library.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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
set prompt "\[$|#]"
proc clear_known_hosts {host} {
exec sed -i "/$host/{d}" $::env(HOME)/.ssh/known_hosts
}
proc ssh_expect {password} {
upvar spawn_id spawn_id
expect {
timeout {
puts "Connection timed out"
exit 1
}
"yes/no" {
send "yes\r"
exp_continue
}
"assword:" {
send "$password\r"
exp_continue
}
$::prompt {
}
}
}
proc scp_expect {password} {
upvar spawn_id spawn_id
expect {
timeout {
puts "Connection timed out"
exit 1
}
"yes/no" {
send "yes\r"
exp_continue
}
"assword:" {
send "$password\r"
exp_continue
}
"ETA" {exp_continue}
"100%" {expect eof}
}
}
proc scp_get_dir {host remote_dir local_dir user password} {
clear_known_hosts $host
spawn scp -r $user@$host:$remote_dir $local_dir
scp_expect $password
}
proc scp_get {host remote_dir local_dir user password} {
clear_known_hosts $host
spawn scp $user@$host:$remote_dir $local_dir
scp_expect $password
}
proc scp_put_dir {host remote_dir local_dir user password} {
clear_known_hosts $host
spawn scp -r $local_dir $user@$host:$remote_dir
scp_expect $password
}
proc scp_put {host remote_dir local_dir user password} {
clear_known_hosts $host
spawn scp $local_dir $user@$host:$remote_dir
scp_expect $password
}
proc ssh_login {host user password} {
upvar spawn_id spawn_id
clear_known_hosts $host
spawn ssh -o ServerAliveCountMax=6 -o ServerAliveInterval=10 -l $user $host
ssh_expect $password
}
proc ssh_login_interact {host user password} {
ssh_login $host $user $password
interact
}
proc gdb_run_program {program} {
upvar spawn_id spawn_id
set timeout 30
send "gdb $program\r"
expect "(gdb)" {send "r\r"}
expect "Starting program" {interact}
}
修订记录
修订时间 | 修订人 | 版本 | 说明 |
---|---|---|---|
TODO | wsxq2 | 1.0 | 初稿 |