0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【TeraTermマクロ】踏み台Ciscoスイッチから別Ciscoスイッチにtelnetログインしてshowログを採取する方法(showコマンド全結果を1つのログに記録)

Last updated at Posted at 2019-12-16

【事前準備】
・teraterm.exeを起動したら1から順番に展開されデフォルトで設定を進行していき「追加タスクの選択」で「.ttlファイルをttpmacro.exeに関連付ける」にチェックを入れること
・teratermの送信遅延設定をどちらも0にしないこと
・teratermログの自動採取を解除すること
・ttlファイル・commandテキスト・hostlistテキストは同じフォルダ内に置くこと
・ログを生成するフォルダの場所は事前に把握しておくこと
・別テキストに以下2つを用意
「command.txt」
show running-config
show logging
show version
など、表示結果が欲しいコマンド
「hostlist.txt」
1.1.1.254
1.1.1.253
1.1.1.252
1.1.1.251
など、ログインしたいホストアドレス

■TTLファイル説明■
*ファイルの書き直しは拡張子をtxtに直して修正する
*踏み台機器にコンソールで接続しteratermの「コントロール」→「マクロ」で開始
*showコマンド結果全部を1つのログに記録
*enableとVTYパスワードが全台同じ想定

■TXTファイル説明■
*コマンド&ホストリストは一覧の最終行で改行禁止(最終行の下に行を作らない)


マクロここから↓↓↓

;■■■■■■■■■■パスワード■■■■■■■■■■			
PASSWORD='hoge'			
;↑全スイッチ共通のパスワード想定			
;■■■■■■■■■■■■■■■■■■■■■■■■■			
			
sendln ''			
wait '>'			
sendln 'en'			
wait 'Password:'			
pause 2			
sendln PASSWORD			
wait '#'			
pause 2			
sendln 'terminal length 0'			
wait '#'			
sendln ''			
wait '#'			
			
sendln 'show running-config | inc hostname'			
wait 'hostname'			
recvln			
strcopy inputstr 1 8 Host_Name			
;*************************************************			
;※↑show runのhostnameから始まる行で「hostname」のあと1~8文字目をHost_Nameとして使用する			
;文字数が違うなら修正して使用する			
;*************************************************			
			
fileopen FHcom 'command.txt' 0			
while 1			
filereadln FHcom comline			
if result = 1 then			
break			
endif			
			
    getdate DATE '_%Y-%m%d-%H%M%S.log'			
    filename = Host_Name			
    strconcat filename '_'			
    strconcat filename 'all command'			
    strconcat filename DATE			
			
    pause 2			
    sendln ''			
    wait '#'			
			
logopen filename 0 0			
			
    sendln comline			
    wait '#'			
    pause 2			
    sendln ''			
    wait '#'			
    pause 2			
endwhile			
			
fileclose FHcom			
logclose			
			
sendln ''			
wait '#'			
			
;■■■■■■■■■■■■■■■■■■■■■■■■■			
;★★★★★★★★次のスイッチにtelnet★★★★★★★★			
;■■■■■■■■■■■■■■■■■■■■■■■■■			
			
fileopen FHtelnet 'hostlist.txt' 0			
:telnetloop			
filereadln FHtelnet telnetline			
if result goto telnetclose			
			
TELNET = telnetline			
			
pause 2			
sendln 'telnet ' TELNET			
wait 'Password:'			
pause 2			
sendln PASSWORD			
wait '>'			
sendln 'en'			
wait 'Password:'			
pause 2			
sendln PASSWORD			
wait '#'			
sendln 'terminal length 0'			
wait '#'			
sendln ''			
			
sendln 'show running-config | inc hostname'			
wait 'hostname'			
recvln			
strcopy inputstr 1 8 Host_Name			
;*************************************************			
;※↑show runのhostnameから始まる行で「hostname」のあと1~8文字目をHost_Nameとして使用する			
;文字数が違うなら修正して使用する			
;*************************************************			
			
fileopen FHcom2 'command.txt' 0			
while 1			
filereadln FHcom2 comline			
if result = 1 then			
break			
endif			
			
    getdate DATE '_%Y-%m%d-%H%M%S.log'			
    filename = Host_Name			
    strconcat filename '_'			
    strconcat filename 'all command'			
    strconcat filename DATE			
			
    pause 2			
    sendln ''			
    wait '#'			
			
logopen filename 0 0			
			
    sendln comline			
    wait '#'			
    pause 2			
    sendln ''			
    wait '#'			
    pause 2			
endwhile			
			
fileclose FHcom2			
logclose			
sendln ''			
wait '#'			
pause 2			
sendln 'exit'			
wait '#'			
			
goto telnetloop			
:telnetclose			
fileclose FHtelnet			
			
pause 2			
sendln ''			
wait '#'			
sendln 'exit'			
			
end			

マクロここまで↑↑↑

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?