In expect, gibt es eine Möglichkeit, den Befehl von Spawn zu zitieren? Ein expect-Skript, das den öffentlichen Schlüssel von einer AWS-Instanz an eine andere AWS-Instanz sendet, spawn manipuliert den Befehl so, dass sshs -i-Option eine ungültige cat Option wird.expect's spawn interpretiert ssh's -i wie es ist
Das Skript.
#!/usr/bin/expect -d
spawn sudo -s cat /root/.ssh/id_rsa.pub | ssh -i /tmp/key.pem [email protected] sudo -s 'dd of=/root/.ssh/authorized_keys oflag=append conv=notrunc'
expect {
"*yes/no*" { send "yes\r"; exp_continue }
}
Der Fehler.
$ pushSSH.expect
expect version 5.44.1.15
argv[0] = /usr/bin/expect argv[1] = -d argv[2] = ./pushSSH.expect
set argc 0
set argv0 "./pushSSH.expect"
set argv ""
executing commands from command file ./pushSSH.expect
spawn sudo -s cat /root/.ssh/id_rsa.pub | ssh -i /tmp/key.pem [email protected] sudo -s 'dd of=/root/.ssh/authorized_keys oflag=append conv=notrunc'
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {13106}
expect: does "" (spawn_id exp4) match glob pattern "*yes/no*"? no
cat: invalid option -- 'i'
Try `cat --help' for more information.
expect: does "cat: invalid option -- 'i'\r\nTry `cat --help' for more information.\r\n" (spawn_id exp4) match glob pattern "*yes/no*"? no
expect: read eof
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "cat: invalid option -- 'i'\r\nTry `cat --help' for more information.\r\n"
Funktioniert der Befehl, wenn er manuell ausgeführt wird? Ja.
sudo -s cat /root/.ssh/id_rsa.pub | ssh -i /tmp/key.pem [email protected] sudo -s 'dd of=/root/.ssh/authorized_keys oflag=append conv=notrunc'
0+1 records in
0+1 records out
401 bytes (401 B) copied, 7.8214e-05 s, 5.1 MB/s
OS: Red Hat Enterprise Linux Server Version 6.7 (Santiago)
Version 5.44.1.15
Ich glaube nicht, können Sie Übergeben Sie eine Shell-Pipeline an '' spawn' ', wenn Sie nicht 'sh -c" cat ... | ssh ... "' spawnen sollten. – larsks
Das war's! Bitte senden Sie Ihre Antwort als Antwort und ich werde Ihre Antwort abstimmen. – user2569618