0
rsync
pexpect
のファイルがあります。すべてのソースファイルが動作していないことを確認するために提供しているグロブストリングの引数が表示されます。 pexpectでrsyncを呼び出す:グロブ・ストリングが機能しない
それの要旨は次のようなものです...
import pexpect
import sys
glob_str = (
"[0-9]" * 4 + "-" +
"[0-9]" * 2 + "-" +
"[0-9]" * 2 + "-" +
"[A-B]" + "*"
)
SRC = "../data/{}".format(glob_str)
DES = "[email protected]:" + "/path/to/dest/"
args = [
"-avP",
SRC,
DES,
]
print "rsync" + " ".join(args)
# Execute the transfer
child = pexpect.spawn("rsync", args)
child.logfile_read = sys.stdout # log what the child sends back
child.expect("Password:")
child.sendline("#######")
child.expect(pexpect.EOF)
は、シェルで
building file list ...
rsync: link_stat "/Users/U6020643/git/ue-sme-query-logs/code/../data/[0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]\-[A-B]*" failed: No such file or directory (2)
0 files to consider
...
同じコマンドの実行が正常に動作します...これで失敗
rsync -avP ../data/[0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]\-[A-B].csv [email protected]:/path/to/dest/
Pexpectは、リダイレクト、パイプ、ワイルドカード(>、|、または*)などのシェルメタ文字を解釈しないことに注意してください。これはよくある間違いです。コマンドを実行して別のコマンドでパイプしたい場合は、シェルも起動する必要があります。
しかし、そう...アクセス許可の問題に
...
args = [
"rsync",
"-avP",
SRC,
DES,
]
...
child = pexpect.spawn("/bin/bash", args) # have to use a shell for glob expansion to work
...
ラン
/usr/bin/rsync: /usr/bin/rsync: cannot execute binary file
ありがとうございました。よく働く。私はこれをドキュメントで見落としました。 –