tera term的ttl腳本使用方法

介紹幾個經常使用的命令
ssh

a. 經過Tera Term鏈接PFC所在的機器以及斷開鏈接oop

經過TTLconnect/disconnect命令實現測試

Connectspa

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

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

Disconnect字符串

disconnect  
get

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

b.    經過log記錄全程操做過程,最終經過比對log確認測試結果。cmd

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

相關文章
相關標籤/搜索