TeratermMacroでのCiscoのログ取り(複数機器対応)
過去のMacroが見つかったので備忘として
同じフォルダに対象機器機器リストのテキストとコマンドリストを設置すれば読み取り複数台での取得が可能
機器リストは下記の順で”,”で区切った情報を記載
#IPaddress,hostname,username,password,enablepass
ipfile = '1_Device_list.txt'
separator = ','
fileopen IPLIST ipfile 0
while 1
filereadln IPLIST buf
if result = 1 Break
Strlen buf
If result = 0 continue
Strmatch buf '#'
If result <> 0 continue
if result then
break
endif
strsplit buf separator
IPaddress = groupmatchstr1
Hostname = groupmatchstr2
Username = groupmatchstr3
pass = groupmatchstr4
enablepass = groupmatchstr5
COMMAND = IPaddress
strconcat COMMAND ':23 /nossh /T=1'
connect COMMAND
;wait 'username:'
;sendln Username
wait 'Password:'
sendln pass
wait '>'
sendln 'en'
wait 'Password:'
sendln enablepass
wait '#'
;log save at same folder
getdir DIR
changedir DIR
Filename = ''
strconcat Filename Hostname
strconcat Filename '_'
strconcat Filename 'Log'
strconcat Filename '_'
strconcat Filename '%Y'
strconcat Filename '%m'
strconcat Filename '%d'
strconcat Filename '%H'
strconcat Filename '%M'
strconcat Filename '.txt'
logopen Filename 1 1
;load command
fileopen cmd 'command.txt' 0
:freadloop
filereadln cmd buf
if result goto breakloop
sendln buf
wait '#'
goto freadloop
:breakloop
fileclose cmd
wait '#'
pause 3
sendln ' exit'
unlink
endwhile
fileclose IPLIST
end