Search code examples
linuxexpectsleszypper

expect: couldn't execute "/usr/bin/zypper patch": no such file or directory


I wrote an expect script

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

but even though I have the zypper with full path, it fails:

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:~ #

although I can reach my purpose with a "zypper patch -y --with-interactive" but I would be really interested, how to do this in expect!


Solution

  • Simply remove the quotes from the spawn line.

    spawn /usr/bin/zypper patch
    

    Currently, you are trying to execute the command zypper patch in the /usr/bin directory, and clearly no such file exists.