18

ランニング:

my_machine~/opt/ams/data/ep/success$ expect -c "spawn /usr/bin/scp xmlEventLog_2010-03-22T14-28-36_PFS_1_2.xml adaptive@10.10.12.17:/opt/ams/epf_3_4/xmlEventLog_2010-03-22T14-28-36_PFS_1277900174_2.xml; expect { '*password:*' { send 'ad'\r\n }}"

私はまだパスワードを求められているので、うまくいかないようです。

spawn /usr/bin/scp xmlEventLog_2010-03-22T14-28-36_PFS_1_2.xml adaptive@10.10.12.17:/opt/ams/epf_3_4/xmlEventLog_2010-03-22T14-28-36_PFS_1277900174_2.xml
adaptive@10.10.12.17's password: 

ascriptとして実行すると、問題なく実行されます。

my_machine~/opt/ams/data/ep/success$ ./try.sh
spawn /usr/bin/scp xmlEventLog_2010-03-22T14-28-36_PFS_1_2.xml adaptive@10.10.12.17:/opt/ams/epf_3_4/xmlEventLog_2010-03-22T14-28-36_PFS_1277900174_2.xml
adaptive@10.10.12.17's password:
xmlEventLog_2010-03-22T14-28-36_PFS_1_2.xml                                                                      100%   13MB  13.2MB/s   00:01
my_machine~/opt/ams/data/ep/success$ cat try.sh
#!/bin/bash
expect -c "
        spawn /usr/bin/scp xmlEventLog_2010-03-22T14-28-36_PFS_1_2.xml adaptive@10.10.12.17:/opt/ams/epf_3_4/xmlEventLog_2010-03-22T14-28-36_PFS_1277900174_2.xml
        expect {
          "*password:*" { send "ad"\r\n; interact }
          eof { exit }
        }
        exit
        "

my_machine~/opt/ams/data/ep/success$

これをスクリプトではなく 1 行のコマンドで実行したいと考えています。誰かアイデアはありますか?

前もって感謝します

私は以下の自分の質問に答えました

4

2 に答える 2

15

わかりました: 次のコードは、Sean_Lilly.zip というファイルを、パスワードを入力せずに、私のボックスから別のボックスに scp します。

expect -c "spawn /usr/bin/scp Sean_Lilly.zip adaptive@10.10.12.17:/opt/ams/epf_3_4/Sean_Lilly.zip; sleep 5; expect -re \"password\"; send \"ad\r\n\"; set timeout -1; expect -re \"100%\";"

これは、2 つのボックス間でパスワードなしの ssh アクセスを設定することで実行できることはわかっていますが、expect を使用して 1 つのコマンド ラインで実行したかったのです。インスピレーションをくれたファジーロリポップに感謝します。expect -d -c "spawn を実行すると、正規表現が十分かどうかなど、何が起こっているかについて優れたデバッグが得られることに注意してください

于 2010-07-29T20:40:59.747 に答える
3

;最後のコマンドの最後にある最初の1行の例が欠落しています。そして、パスワードをパターンマッチングするためのより良い方法があります。

次のことを試してください。

expect -c "spawn /usr/bin/scp xmlEventLog_2010-03-22T14-28-36_PFS_1_2.xml adaptive@10.10.12.17:/opt/ams/epf_3_4/xmlEventLog_2010-03-22T14-28-36_PFS_1277900174_2.xml; expect -re \".*password.*\"; send 'ad\r\n';"
于 2010-07-29T19:20:45.833 に答える