Reputation: 895
I have the following script running successfully. However if I try to use a wildcard, to copy multiple files, it throws an error, saying “No such file or directory”.
This code works:
#!/usr/bin/expect -f
spawn scp file1.txt [email protected]:/temp1/.
expect "password:"
send "iamroot\r"
expect "*\r"
expect "\r"
The following doesn't work:
#!/usr/bin/expect -f
spawn scp * [email protected]:/temp/. #fails here
….
Upvotes: 5
Views: 14213
Reputation: 7735
The *
is usually expanded by the shell (bash), but in this case you shell is expect
. I suspect that expect
is not expanding the *
.
try:
spawn bash -c 'scp * [email protected]:/temp/.'
explanation:
#!/usr/bin/expect -f
spawn echo *
expect "*"
spawn bash -c 'echo *'
expect "file1 file2…"
Upvotes: 8
Reputation: 15508
AFAIK scp defaults to file copy while bash might expand * to directories also, if any is found in the current path.
Perhaps trying a -r
(recursive) could solve your problem (not sure as I can't test the scenario right now)?
Or if you do not want to copy the whole folder structure, you could use scp *.txt ...
depending on your needs.
Upvotes: -1