python-paramiko(linux2のPython 2.7.9)を使用してリモートマシンでsudoコマンドを実行しようとしています 以下はコードです。私はそのが正常に動作し、一方、私はpythonで同じコードを実行すると、それは、異なる出力を毎回与えているコード>>> CMDLINEパスワード入力が必要なSudoを必要とするリモートサーバでコマンドを実行する - Paramiko
import paramiko
import sys
import time
def send_string_and_wait(command, wait_time, should_print):
shell.send(command)
time.sleep(wait_time)
receive_buffer = shell.recv(1024)
if should_print:
return receive_buffer
dbname='test'
cl='testdb'
host='testhost'
owner='uname'
passwd='p'
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(str(host), username=str(owner), password=str(passwd), port=22)
shell = client.invoke_shell()
send_string_and_wait("sudo su - oracle\n", 1, True)
send_string_and_wait(str(passwd) + "\n", 1, True)
a=send_string_and_wait("sh Validation_Final.sh" + str(' ') + str(dbname) + str(' ') + str(cl) + "\n", 0, True)
print a
client.close()
を実行したときに、任意のアドバイスや提案は大歓迎されます、ありがとうございました君は!
ご回答ありがとうございます。私はsudo -kを試していますが、運はありません。興味深いことに、dbnameやクライアントの値をハードコードするときにはうまくいきました。 "" "send_string_and_wait( 'sh /orashare/ettool/Validation_Final.sh dbname client' +" \ n "、1、True)" ""] – Prince
しかし、 "+ str(db)+" "+ str(cl)+" \ n "、0、True)" msgstr "変数を渡すときに問題に直面しています"#:src/""文法の問題でなければならないと思います。間違っていると私を修正してください。 – Prince
'-k'を使うと、リモートサーバが一貫した動作をするようになります。しかし、パスワードを尋ねるときにはシェル記号( '>'や '$'など)を使用しないので、paramikoがそれらのうちの1つのみを待っている場合はブロックされます。 – Mike