linux - 在 Expect 中产生的 rsync 在 10-15 秒后停止
问题描述
我正在尝试通过编写脚本来自动化一项非常繁琐的任务。理想情况下,脚本应该:
- 为列表中的每个目录创建目录。
rsync
从服务器到 working_dir 的一组文件。- 在一组文件上运行 FastQC
working_dir/$FOLDERNAME
- 删除文件和目录。
rsync
提示我输入密码,因此我将其集成到期望函数中。密码输入似乎工作正常,因为 rsync 开始同步。但是,在 10-15 秒后,同步会取消 rsync,而是直接跳转到下一步。有谁知道问题可能是什么?
有问题的脚本如下:
#!/bin/bash
# Change directory to working_dir.
cd /tmp/working_dir
# Load fastqc
module load fastqc/0.11.9
# Function for inputting password prompt rsync
function f_rsync
{
/usr/bin/expect <<EOF
spawn rsync -P username@host.something.com:/something/$FOLDERNAME/*.fastq.gz /tmp/working_dir/$FOLDERNAME
expect "Enter passphrase for key '/home/username/.ssh/id_rsa':"
send "PASSWORD\n"
expect eof
EOF
}
for FOLDERNAME in 2020-02-09 2020-02-10 2020-02-12 2020-04-06 2020-04-07 2020-04-17 2020-04-20 2020-04-22 2020-05-04 2020-08-18 2020-08-19 2020-08-21 2020-08-28 2020-11-02 2020-11-20 2020-12-17 2021-01-26 2021-02-24 2021-02-27 2021-03-01 2021-03-02 2021-03-03 2021-03-15 2021-03-16 2021-04-23 2021-04-26 2021-05-29 2021-05-31 2021-06-02 2021-07-19 2021-07-28 2021-08-08 2021-08-09 2021-08-12 2021-08-13 2021-08-25 2021-08-27;
do
mkdir $FOLDERNAME
f_rsync
fastqc -t 40 -o /home/username/ /tmp/working_dir/${FOLDERNAME}/*.fastq.gz
rm ${FOLDERNAME}/*
rmdir ${FOLDERNAME}
done
解决方案
Expect 的默认超时时间为 10 秒,因此expect eof
会在 10 秒后返回。您可以使用更改默认超时
set timeout 300 ;# use -1 for no timeout
或为每个expect
命令使用显式超时:
expect -timeout 300 eof
推荐阅读
- youtube - 如何删除更多视频的删除 youtube 嵌入代码
- php - Cakephp Sendgrid没有附加附件
- java - 我应该对我的 Java 应用程序进行什么调整以使其停止崩溃?
- react-native - expo -base64 图像从相机检索后未动态显示
- java - JVM 时间同步选项
- python - 如何以 sudo 用户身份执行 pexpect spawn 命令?
- android - 为什么我得到,.dex 文件中的方法引用数不能超过 64K 错误。将 dexguard 版本更新到 8.3.03 后?
- python - 通过调用该列表中的最后一个对象直到它返回 None 来构建列表的 Pythonic 方式
- .htaccess - 将现有项目的旧域重定向到新域
- javascript - 如何从不同的提交按钮将不同的参数传递给 ng-submit?