tera term的ttl指令碼使用方法

來源:互聯網
上載者:User

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指令碼了。(完)

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.