Created
October 13, 2015 12:19
-
-
Save toya33/075e0e66732d1a54897f 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
expect_sample.sh | |
-------------------------------------------------------------- | |
#!/bin/sh | |
COMMAND="ls -la" | |
expect -c" | |
set timeout 5 | |
spawn env LANG=C /usr/bin/ssh UserName@host | |
expect \"\\\% \" | |
# ↑ホワイトスペースが必要!(zshの場合のみ確認) | |
send \"${COMMAND}\n\" | |
expect \"\\\% \" | |
exit 0 | |
" | |
-------------------------------------------------------------- | |
上記を実行すればUserName@hostにsshでログインしコマンド"ls -la" | |
を自動で実行してくれる | |
個人的に必要なこととして、実行結果のみを持ってきて、ログに吐き出す場合は以下 | |
expect_sample_2.sh | |
-------------------------------------------------------------- | |
#!/bin/sh | |
COMMAND="ls -la" | |
COMMAND_RESULT=`expect -c" | |
set timeout 5 | |
spawn env LANG=C /usr/bin/ssh UserName@host | |
expect \"\\\% \" | |
send \"${COMMAND}\n\" | |
expect \"\\\% \" | |
exit 0 | |
"` | |
echo "$COMMAND_RESULT" | cat | sed -e '1,7d' -e '$d' > test.log | |
-------------------------------------------------------------- | |
もう少しなんとか見やすくしたいなー |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment