본문 바로가기

Tools

TeraTerm - 테라텀에서 매크로 기능 사용 (SSH 자동로그인 및 명령 실행하기)

테라텀에는 매크로 기능이 존재한다.


테라텀 시작과 동시에 일련의 명령들을 차례로 수행할 수 있는 기능이다.


SSH로 자동 접속하여 명령을 실행하는 방법을 기준으로 설명한다.


방법은 아래와 같다.


1. 매크로 파일 생성

test.ttl

hostname = '192.168.1.251'
username = 'root'
password = '#testpassword'
command = 'ssh root@node1'

msg = hostname

 

strconcat msg ':22 /ssh /auth=password /user='
strconcat msg username
strconcat msg ' /passwd='
strconcat msg password

 

connect msg

 

wait '#'
sendln command

 

wait '#'
sendln 'ls'


2. cmd창에서 테라텀 실행시 /M 옵션을 사용한다.

C:\teraterm-4.91> ttermpro.exe /M=C:\Users\test.ttl



매크로에 대해 설명을 하자면,


hostname, username, password, command, msg 는 변수이며,

strconcat은 변수에 문자열을 이어 붙이는 함수이고,

connect는 세션에 연결하는 함수이고,

wait은 해당 문자열이 나타날때까지 기다리는 함수이고,

sendln은 해당 문자열을 전송하는 함수이다.


wait과 sendln을 사용하여 여러 명령을 수행 가능하다.