(TTL)TeraTermマクロによるCiscoルータ、スイッチのリストア

何をするか

Ciscoルータ、スイッチの現在のconfigを削除して
別途テキストにて用意したconfigを流し込む

事前準備

 ・コンソール経由で接続
 ・コンフィグが記載されたtxt(基本的にはsh runのコピーでOK)が以下のフォルダに存在する
  C:\Users\engineer\Desktop\TTL\config\
  上記のフォルダに「ホスト名.txt」の形式で保存して下さい

コード

inputbox 'リストアする機器のホスト名を入力して下さい(例:SW1)' '例:SW1'
commandlist_path = 'C:\Users\engineer\Desktop\TTL\config\'
timeout = 5
;;;COM番号を変更する場合はここを修正
connect '/C=3'
 
sendln
sendln

wait '>'
sendln 'en'
;;;特権モードのパスワードが無いときは下記2行をコメントアウトして下さい
wait 'Password'
sendln 'password'
;;;ここまで(上の行は特権パスワードを記載して下さい)
wait '#'
sendln 'erase startup-config'
pause 1
sendln
wait '#'
pause 3
sendln 'reload'
wait 'System configuration has been modified. Save? [yes/no]'
sendln 'yes'
sendln
wait 'Proceed with reload? [confirm]'
sendln
timeout = 500
sendln
wait 'Press RETURN to get started!' 'state to down' 'state to up' 'Would you like to enter the initial configuration dialog? [yes/no]:'
timeout = 5
sendln
wait 'Would you like to enter the initial configuration dialog? [yes/no]:'
sendln 'no'
sendln
wait 'Press RETURN to get started!' 'state to down' 'state to up'
timeout = 5
sendln
sendln
wait '>'
sendln 'en'
wait '#'
sendln 'conf t'
wait '#'

;;;txt内のコンフィグを上から順に読み込み

	hostname = inputstr
	commandlist = commandlist_path
	strconcat commandlist hostname
		filereadln fc command
	strconcat commandlist '.txt'
	
	fileopen fc commandlist 0
	
	while 1
		if result = 1 then
			break
		endif
		
		sendln command
		mpause 500
		
		cmd = 'crypto key generate rsa'
		strcompare cmd command
		
                ;;;特権モードのパスワードが無いときは下記4行をコメントアウトして下さい
		if result=0 then
			wait 'How many bits in the modulus'
			sendln '2048'
		endif
                ;;;ここまで
	endwhile
	fileclose fc
	
    sendln 'exit'

実行後に入力ダイアログが表示されるので、ホスト名を入力して下さい