1. 環境構築
1.安裝Tera Term。
下載路徑如下:
http://logmett.com/index.php?/download/tera-term-469.html
2.安裝可啟動並執行PFC環境
2. 運用TTL指令碼進行自動化的測試
TTL指令碼的命名一覽和相關介紹請參考Tera Term的help檔案。
TTL指令碼作成方法:
指令碼的作成比較簡單,我這也不說什麼了,我就簡單介紹下基本上都要用到的幾個命令。
a. 通過Tera Term串連PFC所在的機器以及中斷連線
通過TTL的connect/disconnect命令實現
Connect:
connect '192.168.137.27 /ssh /auth=password /user=username /passwd= passwd'
註:其中username是使用者名稱,passwd是密碼
Disconnect:
disconnect
0
註:disconnect後面指定參數0,這樣就不彈出確認框了。
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為0時,則為逾時。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
2,生產ttl指令檔test.ttl
;###connect host
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
looptimes = 1 ;
while looptimes < 11
;###run cmd
sendln "ls -l"
wait "#"
looptimes = looptimes + 1
endwhile
;###closelog
Logclose
;###disconnect
disconnect
closett
執行bat檔案就可以運行ttl指令碼了。(完)