tera term的ttl腳本使用方法

分類:IT技術 時間:2017-01-30

介紹幾個常用的命令

a. 通過Tera Term連接PFC所在的機器以及斷開連接

通過TTLconnect/disconnect命令實現

Connect

connect '192.168.137.27 /ssh /auth=password /user=username /passwd= passwd'

註:其中username是用戶名,passwd是密碼

Disconnect

disconnect  

註:disconnect後面指定參數,這樣就不彈出確認框了。

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>RemarksPauses for <time> seconds. 

 

Sendln:(發送命令並換行)

sendln <data1> <data2>....

RemarksCauses Tera Term to send characters followed by a new-line character to the host.            

Send:(發送命令)

send <data1> <data2>....

RemarksCauses 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> ...]

RemarksPauses 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> ...]

RemarksPauses 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腳本了.


Tags: character password seconds 測試結果 用戶名

文章來源:


ads
ads

相關文章
ads

相關文章

ad