0

新しい言語をリモート ファイルにプッシュする最初の期待スクリプトを作成しようとしています。

これは私がこれまでに持っていたもので、実際には機能していません:

#!/usr/bin/expect

set fid1 [open ./hosts.list r]
set hosts [read -nonewline $fid1]
close $fid1

set banner_cmd "cat > /tmp/new_sshd_banner << EOF


<New Language Goes Here>


EOF"
send "\n"

stty -echo
send_user "Enter password for remote sudo: "
expect_user -re "(.*)\n"
stty echo
set pass $expect_out(1,string)
send "\n"

foreach host [split $hosts "\n"] {
    eval spawn "/usr/bin/ssh $host"
    expect {
        -re "RSA key fingerprint" {send "yes\r"}
        timeout {puts "Host is known"}
    }

    expect "$host"
    send "sudo mv /etc/file /etc/file.orig"
    expect "assword"
    send $pass

    expect "$host"
    send "sudo $file_cmd"

    expect "$host"
    send "sudo mv /tmp/file /etc/file

}

実行すると、次のように表示されます。

opensuse @ 15:10 ~/bin> ./fix_file.exp 

Enter password for remote sudo: 
spawn /usr/bin/ssh server

<New Language Goes Here>


Last login: Fri Aug 31 19:52:45 2012 from 10.152.81.105
[user@server ~]$ Host is known
sudo cat > /tmp/new_file << EOF 
> 
> 
> <New Language Goes Here> 
> 
> EOFsudo mv /etc/file /etc/filePASSWORD*missing "
    while executing
"send "sudo mv /tmp/file /etc/file

"
    ("foreach" body line 17)
    invoked from within
"foreach host [split $hosts "\n"] {
    eval spawn "/usr/bin/ssh $host"
    expect {
        -re "RSA key fingerprint" {send "yes\r"}
        timeout {puts "Host i..."
    (file "./fix_file.exp" line 45)

すぐにはわからないことの 1 つは、ユーザーから取得したパスワードを mv コマンドの出力に追加することです。

これのどこが間違っていますか?

4

1 に答える 1

1

エラーの正確な内容:

missing "
    while executing
"send "sudo mv /tmp/file /etc/file

次の行の後に「終わり」がありません。

    send "sudo mv /tmp/file /etc/file
于 2012-09-04T20:40:47.803 に答える