http://hacker81305.pixnet.net/blog/post/4237010-teraterm-macro-%E6%95%99%E5%AD%B8
http://shutdown2110.blogspot.tw/2015/10/tera-termttl.html
http://shutdown2110.blogspot.tw/2015/10/tera-termttl.html
介紹幾個常用的指令
a.通過Tera Term連接PFC所在的機器以及斷開連接
通過TTL的connect/disconnect命令實現
Connect:
connect '192.168.137.27 /ssh /auth=password /user=username /passwd= passwd'
注:其中username是用戶名,passwd是密碼
Disconnect:
disconnect
注:disconnect後面指定參數,這樣就不彈出確認框了。
connect '/c=3 /baud=115200'
; C=3 是com port3 ,baud rate =115200
b.通過log記錄全程操作過程,最終通過比對log確認測試結果。
通過logopen/logclose命令來寫log
logopen:
logopen filename 0 1 1
注:filename最好設成命令名,不通ttl腳本不要重複。也可以帶執行的時間,
例如:Show_candidate_config_ 20110426-130939.log
方法如下:
gettime timestr "%Y%m%d-%H%M%S"
getdir mdir
sprintf2 filename '%s\ Show_candidate_config _%s.log' mdir timestr
logclose :
logclose
c.測試項作成時可能用到的命令
Pause:(暫停)
pause <time> Remarks :Pauses for <time> seconds.
Sendln:(發送命令並換行)
sendln <data1> <data2>....
Remarks :Causes Tera Term to send characters followed by a new-line character to the host.
Send :(發送命令)
send <data1> <data2>....
Remarks :Causes Tera Term to send characters to the host.
If <data> is a string, the string is sent to the host.
If <data> is an integer, its lowest-order byte (0-255) is regarded as an ASCII code of the character, and the character is sent to the host. 例如:按Tab 鍵的命令是send #9
wait:( 等待匹配的字符串出現)
wait <string1> [<string2> ...]
Remarks :Pauses until one of the character strings is received from the host, or until the timeout occurs. Maximum number of the strings is 10.
注:使用這個命令是需要設置timeout 時間,命令的返回結果保存在resault 變量中,當resault 為時,則為超時。Timeout 設置命令如下:
timeout=1 /* 等號後面的值為整數,設為負則是無限等待*
waitln:( 等待整行匹配的字符串出現)
waitln <string1> [<string2> ...]
Remarks :Pauses until a line which contains one of the character strings is received from the host, or until the timeout occurs. Maximum number of the strings is 10.
注意點同上 其他命令例如if,then,elseif,else,endif,goto 等請參考help 文件。
腳本製作注意
a. 不同的ttl 腳本內指定的Log 文件名不能重複。
b. 腳本的最後部分請清空測試環境,以便下一個ttl 腳本執行。
c. 在執行比較緩慢的地方,例如連接機器時,請追加pause 命令
d. 腳本盡量寫得簡潔短小,以便式樣發生變更時易於更改。
e. 必要的時候可以追加註釋
例子:
1,在window 下創建bat文件
"C:\Program Files\teraterm\ttpmacro.exe" "D:\My Kownhow\TTL\test.ttl"
exit
exit
2,生產ttl腳本文件test.ttl
;###connect host
connect '172.28.92.23 /ssh /auth=password /user=root /passwd=password'
connect '172.28.92.23 /ssh /auth=password /user=root /passwd=password'
pause 1
;###create log
gettime logstr "log-%Y%m%d-%H%M%S.txt"
getdir curdir
sprintf '%s\%s' curdir logstr
filename = inputstr
logopen filename 0 1 1
logwrite 'Log start'#13#10
getdir curdir
sprintf '%s\%s' curdir logstr
filename = inputstr
logopen filename 0 1 1
logwrite 'Log start'#13#10
looptimes = 1 ;
while looptimes < 11
;###run cmd
while looptimes < 11
;###run cmd
sendln "ls -l"
wait "#"
looptimes = looptimes + 1
endwhile
wait "#"
looptimes = looptimes + 1
endwhile
;###closelog
Logclose
Logclose
;###disconnect
disconnect
closett
disconnect
closett
執行bat文件就可以運行ttl腳本.