i've installed expect,and checked the path not wrong(which expect)

my shell program is to call the rsync,here's the source code

#!/usr/bin/expect -f

set timeout -1
spawn rsync -ravz /home/mypath  username@remotehost:/data/
expect "*password:"
send "mypassowrd\r"
interact

save it as aaa.sh run the file

sh aaa.sh 

the terminal give result

: not foundaaa.sh:
aaa.sh: 4: aaa.sh: spawn: not found
": no such file or directoryd:
aaa.sh: 6: aaa.sh: send: not found
: not foundaaa.sh: interact

set it executable and run it by

 ./aaa.sh

give the result

": no such file or directory

have no idea why this happens,seems the expect wouldn't be call in shell file. directly type expect is ok,but doesn't make sense.

有帮助吗?

解决方案

I believe that is because you are trying to interpret expect commands with sh.

What I would do is the following. Save your script with the standard expect file extension .exp (this is just for clarity), make it an executable, and then just run it from your shell.

mv aaa.sh aaa.exp
chmod u+x aaa.exp
./aaa.exp

You have already let your script know where the expect binary is located, so that should be enough for you.

Let me know how that works out for you.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top