ここの手順に従いましたhttp://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely-different/
Python経由でsshを使用してサーバーに接続します。正常に接続してコマンドを送信できます。
ただし、stderr.readlines() を実行すると、コマンドが正しく実行されたように見えても、毎回以下のエラー メッセージが表示されます。接続を閉じて Python を再起動しましたが、結果は同じです。
Python のサンプルは次のとおりです。
>>> stdin, stdout, stderr = myssh.exec_command("xyz")
>>> stderr.readlines()
['which: no php in (/usr/bin:/bin:/usr/sbin:/sbin:/big/dom/mydomain/pear/drush)\n', '/big/dom/mydomain/pear/drush/drush: line 89: exec: : not found\n', 'bash: xyz: command not found\n']
drush をインストールしましたが、問題なく動作しているようです。サーバーで「どのphp」と入力すると、上記のエラーメッセージの代わりに、サーバーがどこにあるかが通知されます。他のコマンドを送信して、意図的にエラーメッセージを取得して、何かがクリアされたかどうかを確認しました。代わりに、最後に物事を追加しました。
エラー メッセージに従って、参照されている drush ファイルを確認しました。89行目は次のとおりです。
exec "$php" $php_options "$SCRIPT_PATH" --php="$php" --php-options="$php_options" "$@"
「which php」コマンドは、この行の上のチャンクの $php 変数から来ていると思います
if [ ! -z "$DRUSH_PHP" ] ; then
# Use the DRUSH_PHP environment variable if it is available.
php="$DRUSH_PHP"
else
# Default to using the php that we find on the PATH.
# Note that we need the full path to php here for Dreamhost, which behaves oddly. See http://drupal.org/node/662926
php=`which php`
# We check for a command line (cli) version of php, and if found use that.
which php-cli >/dev/null 2>&1
if [ "$?" = 0 ] ; then
php=`which php-cli`
fi
# On MSYSGIT, we need to use "php", not the full path to php
if [ ! -z "$MSYSTEM" ] && [ "x${MSYSTEM:0:5}" = "xMINGW" ] ; then
php="php"
fi
fi
ファイルの全文はこちら: http://pastebin.com/29AXmHKF
drush コマンドを実行しようとすると、同じエラーが発生します。しかし、python/paramiko を使用せずにサーバーに直接ログインするだけで、drush コマンドは正常に機能します。