Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wildcard in expect script doesn't work

Tags:

testing

expect

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
….
like image 220
user1293997 Avatar asked Jun 18 '12 23:06

user1293997


1 Answers

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…"
like image 188
ctrl-alt-delor Avatar answered Sep 27 '22 17:09

ctrl-alt-delor