我有一个脚本,可从ssh服务器下载文件。它运行正常,可以开始下载,但是在下载完成之前会从下载继续进行。有没有办法等到下载完成?我已尝试等待,但只是暂停。
#!/usr/bin/expect
spawn sftp root@ip
expect "password"
send "<password>\r"
expect "sftp>"
send "lcd Desktop\r"
expect "sftp>"
send "cd Desktop\r"
expect "sftp>"
send "get -r File\r"
wait
close
wait
expect
将使用$timeout
设置放弃正在等待的内容,并将继续执行脚本。要一直等到模式匹配,请执行
set timeout -1
所以
expect "sftp>"
send "get -r File\r"
set timeout -1
expect "sftp>"
send "exit\r" ;# exit gracefully
expect eof