I am trying to copy all files but using expect command
I have the following script with expect.dat file
I have the following error, what am I doing wrong or how do I have to build the command to copy the files
command
expect expect.dat
File expect.dat
#!/usr/bin/expect
set src_file "/process/source"
set dest_file "/process/destination"
# Run the cp command and wait for the response
spawn cp -r $src_file $dest_file
expect "*?(y/n)?"
send "y\r"
expect eof
Error
spawn cp -r /process/source /process/destination
send: spawn id exp6 not open
while executing
"send "y\r""
(file "expect.dat" line 8)
CodePudding user response:
"spawn id not open" means the cp
command has already exited so there's no process to send
something to.
If the cp
command might ask you a question, you'll want to expect
either the pattern or eof
expect {
"*?(y/n)?" {send "y\r"; exp_continue}
eof
}
Are you sure you need expect for this at all?
cp -r -f /process/source /process/destination