-1

我写了一个期望脚本

vi /foo/force-zypper-patch.exp
cat /foo/force-zypper-patch.exp
#!/usr/bin/expect

set timeout 300
spawn "/usr/bin/zypper patch"
expect "Continue? [y/n/...? shows all options] (y): " { send "y\r" }
interact

但即使我有完整路径的 zypper,它也会失败:

SERVER1:~ # ssh SERVER2 "/usr/bin/expect -f /foo/force-zypper-patch.exp"
spawn /usr/bin/zypper patch
couldn't execute "/usr/bin/zypper patch": no such file or directory
    while executing
"spawn "/usr/bin/zypper patch""
    (file "/foo/force-zypper-patch.exp" line 4)
SERVER1:~ #
SERVER1:~ # ssh SERVER2 "which zypper"
/usr/bin/zypper
SERVER1:~ #

虽然我可以通过“zypper patch -y --with-interactive”来达到我的目的,但我真的很感兴趣,如何在期望中做到这一点!

4

1 回答 1

0

只需从行中删除引号spawn

spawn /usr/bin/zypper patch

目前,您正在尝试执行目录zypper patch中的命令/usr/bin,显然不存在这样的文件。

于 2020-08-26T17:50:45.927 回答