環境

  • OS X 10.11 El Capitan
  • Vagrant 1.8.1
  • VirtualBox 5.0.20 r106931
  • CentOS 7.2.1511

サーバー側設定

  • シェルスクリプト作成(hello.sh)
$ vim hello.sh
#!/bin/bash
echo "Hello World!"
exit 0
$ chmod +x hello.sh
$ ./hello.sh
Hello World!

クライアント(Mac)側設定

  • Homebrewのインストール
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ source ~/.bash_profile
$ brew -v
Homebrew 0.9.9 (git revision 9a9a; last commit 2016-05-04)
Homebrew/homebrew-core (no git repository)
  • sshpassインストール
$ brew install http://git.io/sshpass.rb
$ which sshpass
/usr/local/bin/shapes
  • シェル起動用Pythonスクリプト作成(hello_shell.py)
# coding: UTF-8
import subprocess

SSH_USER = "User Name"
SSH_PASS = "Password"
SSH_HOST = "192.168.33.10"
CMD = "./hello.sh"

subprocess.call(["sshpass", "-p", SSH_PASS, "ssh", SSH_USER + "@" + SSH_HOST, CMD])

実行

  • クライアント上の "hello_shell.py" を実行(サーバーへSSH自動ログイン後 "hello.sh" を実行)
$ python hello_shell.py
Hello World!

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2016-05-05 (木) 11:44:22 (2913d)