Last active
June 23, 2016 14:05
-
-
Save dehio3/8d0b0c4571468a9d66fbdf764e6b8f18 to your computer and use it in GitHub Desktop.
各ESXiにssh接続し、仮想サーバのサマリー情報を取得するスクリプト(実行シェル)
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
#!/bin/sh | |
#接続するESXiのIPアドレスを設定 | |
servers=" | |
192.168.1.XXX | |
" | |
#接続するESXiのユーザーのパスワードを設定 | |
#今回は全台共通にて存在するrootユーザーにて接続 | |
#接続先のESXiにてrootユーザーのパスワードが全て同じ事が前提 | |
password=******* | |
for s in $servers | |
do | |
expect -c " | |
set timeout 20 | |
#------------------------------------- | |
# vmsvc.summaryの情報をファイル出力 | |
#------------------------------------- | |
spawn bash -c \"cat command | ssh root@$s\" | |
expect { | |
\"password:\" { | |
send \"$password\n\" | |
} | |
\"Password:\" { | |
send \"$password\n\" | |
} | |
} | |
interact | |
#------------------------------------- | |
# 出力したファイルをローカルへ取得 | |
#------------------------------------- | |
spawn scp -p root@$s:/tmp/vmsvc.summary,"*" . | |
expect { | |
\"password:\" { | |
send \"$password\n\" | |
} | |
\"Password:\" { | |
send \"$password\n\" | |
} | |
} | |
interact | |
" | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment