我成功运行了以下脚本。但是,如果我尝试使用通配符复制多个文件,它会抛出一个错误,提示“没有这样的文件或目录”。
此代码有效:
#!/usr/bin/expect -f
spawn scp file1.txt root@192.168.1.156:/temp1/.
expect "password:"
send "iamroot\r"
expect "*\r"
expect "\r"
以下不起作用:
#!/usr/bin/expect -f
spawn scp * root@192.168.1.156:/temp/. #fails here
….
最佳答案
*
通常由 shell (bash) 扩展,但在这种情况下,您的 shell 是 expect
。我怀疑 expect
没有扩展 *
。
尝试:
spawn bash -c 'scp * root@192.168.1.156:/temp/.'
解释:
#!/usr/bin/expect -f
spawn echo *
expect "*"
spawn bash -c 'echo *'
expect "file1 file2…"
关于testing - 期望脚本中的通配符不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11092667/