Last active
January 6, 2018 22:49
-
-
Save sensq/62f529d3b86ce230d69a56a8795ed589 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
## 複数サーバ管理用スクリプト | |
## | |
##### ユーザ変数定義 ##### | |
# RLoginのパス | |
$rlogin_path = ".\RLogin.exe" | |
# サーバ情報テーブル(CSV形式) | |
# 記載順:Name, IP, Port, User, Password, UseEntry | |
## 直接定義する場合 | |
#$records = @( | |
#"Webサーバ_01,192.168.1.11,22,root,password,Default_SSH" | |
#"Webサーバ_02,192.168.1.12,22,root,password,Default_SSH" | |
#"Appサーバ_01,192.168.1.21,22,root,password,Default_SSH" | |
#"Appサーバ_02,192.168.1.22,22,root,password,Default_SSH" | |
#"DBサーバ_01,192.168.1.31,22,root,password,Default_SSH" | |
#"DBサーバ_02,192.168.1.32,22,root,password,Default_SSH" | |
#"dev01_開発用サーバ,192.168.1.101,22,root,password,Default_SSH" | |
#"dev01_Webサーバ,192.168.1.11,22,root,password,Bastion_dev01_SSH" | |
#"dev01_Appサーバ,192.168.1.21,22,root,password,Bastion_dev01_SSH" | |
#"dev01_DBサーバ,192.168.1.31,22,root,password,Bastion_dev01_SSH" | |
#"dev02_開発用サーバ,192.168.1.102,22,root,password,Default_SSH" | |
#"dev02_Webサーバ,192.168.1.11,22,root,password,Bastion_dev02_SSH" | |
#"dev02_Appサーバ,192.168.1.21,22,root,password,Bastion_dev02_SSH" | |
#"dev02_DBサーバ,192.168.1.31,22,root,password,Bastion_dev02_SSH" | |
#) | |
## CSVファイルから読み込ませる場合 | |
$csv_path = ".\server_list.csv" | |
$records = (Get-Content $csv_path) | |
$records = $records[1..($records.Length-1)] # ヘッダ除去 | |
##### メイン処理 ##### | |
# 処理用変数定義(CSV形式の記載順と同じ順で定義すればよい) | |
enum ReferenceIndex { | |
Name | |
IP | |
Port | |
User | |
Password | |
UseEntry | |
} | |
$objs = @() | |
$no = 0 | |
# 表示用オブジェクト作成 | |
$records | %{ | |
$no += 1 | |
# 取得情報を変数に格納 | |
$record = $_.ToString().Split(",") | |
$name = $record[[int]([ReferenceIndex]::Name)] | |
$ip = $record[[int]([ReferenceIndex]::IP)] | |
$port = $record[[int]([ReferenceIndex]::Port)] | |
$user = $record[[int]([ReferenceIndex]::User)] | |
$pass = $record[[int]([ReferenceIndex]::Password)] | |
$entry = $record[[int]([ReferenceIndex]::UseEntry)] | |
# ウィンドウやタブに表示される文字列(任意で変更可) | |
$title = "$name[$ip]" | |
# 上記情報から作成したコマンド | |
$cmd = "$rlogin_path /ip $ip /port $port /user $user /pass '$pass' /title '$title' /entry '$entry' /inuse" | |
# 最終的に表示されるオブジェクトの作成 | |
$obj = New-Object PSCustomObject | |
$obj | Add-Member -NotePropertyMembers @{ | |
No = $no | |
Name = $name | |
IP = $ip | |
Port = $port | |
User = $user | |
Password = $pass | |
UseEntry = $entry | |
接続コマンド = $cmd | |
} | |
$objs += $obj | |
} | |
# テーブル表示 | |
$objs | Out-GridView -PassThru -Title "接続先を選択して下さい" | %{ | |
Invoke-Expression $_.接続コマンド | |
echo $_.接続コマンド | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Name | IP | Port | User | Password | UseEntry | 備考 | |
---|---|---|---|---|---|---|---|
Webサーバ_01 | 192.168.1.11 | 22 | root | password | Default_SSH | ||
Webサーバ_02 | 192.168.1.12 | 22 | root | password | Default_SSH | ||
Appサーバ_01 | 192.168.1.21 | 22 | root | password | Default_SSH | ||
Appサーバ_02 | 192.168.1.22 | 22 | root | password | Default_SSH | ||
DBサーバ_01 | 192.168.1.31 | 22 | root | password | Default_SSH | ||
DBサーバ_02 | 192.168.1.32 | 22 | root | password | Default_SSH | ||
dev01_開発用サーバ | 192.168.1.101 | 22 | root | password | Default_SSH | ||
dev01_Webサーバ | 192.168.1.11 | 22 | root | password | Bastion_dev01_SSH | dev01_開発用サーバからのみ繋がる | |
dev01_Appサーバ | 192.168.1.21 | 22 | root | password | Bastion_dev01_SSH | dev01_開発用サーバからのみ繋がる | |
dev01_DBサーバ | 192.168.1.31 | 22 | root | password | Bastion_dev01_SSH | dev01_開発用サーバからのみ繋がる | |
dev02_開発用サーバ | 192.168.1.102 | 22 | root | password | Default_SSH | ||
dev02_Webサーバ | 192.168.1.11 | 22 | root | password | Bastion_dev02_SSH | dev02_開発用サーバからのみ繋がる | |
dev02_Appサーバ | 192.168.1.21 | 22 | root | password | Bastion_dev02_SSH | dev02_開発用サーバからのみ繋がる | |
dev02_DBサーバ | 192.168.1.31 | 22 | root | password | Bastion_dev02_SSH | dev02_開発用サーバからのみ繋がる |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment