開発メモ

開発用のメモです。

WinScp から Teraterm を起動するときの簡易コマンドファイル

@echo off
rem command : ttermpro.cmd !@ !U !P
rem arg[0]  : ttermpro.cmd
rem arg[1]  : <hostname>
rem arg[2]  : <username>
rem arg[3]  : <password>
rem arg[4]  : -pw
rem arg[5]  : <password>
rem test    : cd %UserProfile%\command
rem test    : ttermpro.cmd $hostname $username $password

SET FORMAT=%DATE:~-10%
SET FORMAT=%FORMAT%-%TIME%
SET FORMAT=%FORMAT:~0,19%
SET FORMAT=%FORMAT:/=%
SET FORMAT=%FORMAT::=%
SET FORMAT=%FORMAT: =0%

REM FORMAT YYYYMMDD-HHMMDD

ECHO FORMAT : %FORMAT%

SET LOG_FILE=/L=C:\var\log\%1_%FORMAT%.log 
ECHO LOG_FILE : %LOG_FILE%


SET HOST1=%1
SET HOST2=%1
SET KT=UTF8

REM CHANGE TUNNEL
IF "%HOST1:~0,3%" == "192" (
    IF "%HOST1%"  == "192.168.0.2" ( SET HOST1=192.168.1.10 )
)

REM HOST1 : CONNECTION HOST
REM HOST2 : TUNNEL HOST

ECHO HOST1 : %HOST1%
ECHO HOST2 : %HOST2%

SET INI_FILE=
IF EXIST "%UserProfile%\.config\teraterm\%HOST1%.ini" (

SET INI_FILE=/FD="%UserProfile%\.config\teraterm\%HOST1%.ini"

)

REM CONFIG FILE
ECHO INI_FILE : %INI_FILE%

IF "%2" == "" ( 
SET USER_REF=
) ELSE (
SET USER_REF=/user=%2
)
REM LOGIN USER
ECHO USER_REF : %USER_REF%

IF "%3" == "" (
SET PASSWORD_REF=
SET AUTO_PASSWORD=
) ELSE (
SET PASSWORD_REF=/passwd=%3
SET AUTO_PASSWORD=/auth=password
)

REM LOGIN PASSWORD
ECHO PASSWORD_REF : %PASSWORD_REF%

REM EXECUTE
start /b ttermpro.exe %HOST1% /ssh /2  %AUTO_PASSWORD% %USER_REF% %PASSWORD_REF% %LOG_FILE% %INI_FILE%
exit 0;
Twitter: @asahina_alice