Read this in other languages: 日本語 | English
Warning
本プロジェクトは開発中です。APIや機能は予告なく変更される可能性があります。 本番環境での使用は推奨しません。
ttlxは、YAML設定ファイルからTera Termマクロ(TTL)スクリプトを生成するツールです。 共通の接続設定やコマンドをプロファイル化することで、複数のスクリプト間での再利用を可能にし、保守性を向上させます。
| TTL機能カテゴリ | 対応状況 | 説明 |
|---|---|---|
| SSH接続 | ✅ 対応 | 多段SSH接続(踏み台サーバー経由) |
| 認証 | ✅ 対応 | パスワード認証(パスワードファイル/直接指定) 公開鍵認証 |
| コマンド実行 | ✅ 対応 | 接続後の任意コマンド実行 |
| エラーハンドリング | ✅ 対応 | タイムアウト処理、接続失敗時の処理 |
| ダイアログ表示 | パスワード入力、エラーメッセージのみ | |
| 変数操作 | パスワードファイル読み込み、文字列連結 |
- 📝 YAML設定: シンプルで読みやすいYAML形式でSSHルートとコマンドを定義
- 🔐 複数の認証方式: パスワード認証と公開鍵認証をサポート
- 🔗 多段SSH接続: 踏み台サーバーやプロキシサーバー経由の接続を自動化
- ✅ バリデーション: わかりやすいエラーメッセージ付きの設定検証機能
git clone https://github.com/JHashimoto0518/ttlx.git
cd ttlx
go build -o ttlx cmd/ttlx/main.gogo install github.com/JHashimoto0518/ttlx/cmd/ttlx@latestversion: "1.0"
profiles:
bastion:
host: bastion.example.com
user: admin
prompt_marker: "$ "
auth:
type: password
password_file: passwords.dat
web-server:
host: 10.0.0.10
user: webadmin
prompt_marker: "$ "
auth:
type: password
password_file: passwords.dat
password_prompt: "password:"
db-server:
host: 10.0.0.20
user: dbadmin
prompt_marker: "$ "
auth:
type: password
password_file: passwords.dat
password_prompt: "password:"
# bastionプロファイルを共用して複数のルートを定義
routes:
to-web-server:
- profile: bastion
- profile: web-server
commands:
- systemctl status nginx
to-db-server:
- profile: bastion
- profile: db-server
commands:
- systemctl status postgresql$ ttlx build config.yml
Generated TTL files:
- to-web-server.ttl
- to-db-server.ttlルートごとにTTLファイルが生成されます。Tera Termで実行してください。
ビルド前に設定ファイルの構文エラーをチェックできます。
$ ttlx validate config.yml
✓ Configuration is valid各プロファイルはSSH接続先を定義します:
profiles:
server_name:
host: ホスト名またはIP # 必須
port: 22 # オプション、デフォルト: 22
user: ユーザー名 # 必須
prompt_marker: "$ " # 必須、プロンプト識別文字列
auth: # 必須
type: password|keyfile
# ... 認証方式固有の設定auth:
type: password
# 以下のいずれかを選択:
password_file: passwords.dat # パスワードファイルから読み込み(推奨)
# 省略時のデフォルト: "passwords.dat"
value: "password" # パスワードを直接記述(テスト用、非推奨)
# 2段目以降のルートステップでは以下が必須:
password_prompt: "password:" # パスワード入力待機文字列パスワードファイルの使用方法:
- Tera Termの
getpasswordコマンドを使用してパスワードファイルから読み込みます - パスワード名はプロファイル名が自動的に使用されます
- パスワードファイルの作成方法はTera Term公式ドキュメントを参照してください
auth:
type: keyfile
path: ~/.ssh/id_rsa # 秘密鍵ファイルのパスSSH接続の順序を定義します:
routes:
multi-hop-connection:
- profile: bastion # 1段目
commands: # 実行するコマンド(オプション)
- su - root
- cd /var/log
- profile: target # 2段目
commands:
- ps auxoptions:
timeout: 30 # 接続タイムアウト(秒)、デフォルト: 30
retry: 3 # リトライ回数(未実装)
log: true # ログ有効化(未実装)
log_file: /tmp/ttlx.log # ログファイルパス(未実装)
auto_disconnect: true # 最終ステップ完了後に自動切断、デフォルト: false(実験的機能)Warning
auto_disconnectは実験的機能です。以下の制限事項があります:
- 各プロファイルの
prompt_markerに一致するプロンプトのみ検出可能 - カスタムプロンプト(独自のPS1設定など)を使用する環境では正しく動作しない可能性があります
suで異なるプロンプトに変わる場合、そのプロンプトがいずれかのプロファイルのprompt_markerに含まれている必要があります
YAML設定からTTLスクリプトを生成:
ttlx build <config.yml> [フラグ]
フラグ:
-o, --output string 出力ディレクトリパス(デフォルト: カレントディレクトリ)
--dry-run ファイルではなく標準出力に出力
例:
$ ttlx build config.yml
Generated TTL files:
- config.ttl
- config_simple-connection.ttl
$ ttlx build config.yml -o output/
Generated TTL files in output/:
- config.ttl
- config_simple-connection.ttlYAML設定を検証:
ttlx validate <config.yml>バージョン情報を表示:
ttlx versionより多くのサンプルは test/fixtures/valid ディレクトリを参照してください:
- simple.yml - 基本的な2段SSH接続
- full.yml - 全機能を使用した設定例
- Go 1.25以降
- golangci-lint(リント用)
go build -o ttlx cmd/ttlx/main.go# 全テスト実行
go test ./...
# カバレッジ付きテスト実行
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
# リント実行
golangci-lint runttlx/
├── cmd/ttlx/ # CLIエントリーポイント
├── internal/
│ ├── cli/ # CLIコマンド
│ ├── config/ # 設定処理
│ └── generator/ # TTL生成
├── test/
│ ├── fixtures/ # テストデータ
│ └── integration/ # 統合テスト
└── docs/ # ドキュメント
コントリビューションを歓迎します!詳細は CONTRIBUTING.md を参照してください。
このプロジェクトはMITライセンスの下で公開されています。詳細は LICENSE ファイルを参照してください。
- Tera Term Project - このツールがスクリプトを生成する対象のターミナルエミュレーター
- Cobra - CLIフレームワーク
- go-yaml - YAMLパーサー