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 Remarks:Pauses for
Sendln:(发送命令并换行)
sendln
If is a string, the string is sent to the host.
If 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
注:使用这个命令是需要设置timeout时间,命令的返回结果保存在resault变量中,
当resault为0时,则为超时。Timeout设置命令如下:
timeout=1 /*等号后面的值为整数,设为负则是无限等待*/
waitln:(等待整行匹配的字符串出现) waitln
使用例子:
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脚本了。(完)