環境

サーバー側設定

$ vim hello.sh
#!/bin/bash
echo "Hello World!"
exit 0
$ chmod +x hello.sh
$ ./hello.sh
Hello World!

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

$ /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)
$ brew install http://git.io/sshpass.rb
$ which sshpass
/usr/local/bin/shapes
# 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])

実行

$ python hello_shell.py
Hello World!

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS