davidlord
davidlord

Reputation: 1

rsync spawned in Expect stopped after 10-15 seconds

I'm trying to automate a very tedious task by scripting it. Optimally, the script should:

  1. Create dir for each dir in list.
  2. rsync a set of files from server to working_dir.
  3. Run FastQC on a set of files in working_dir/$FOLDERNAME
  4. Remove the files and the dir.

rsync prompts me for a password, I therefore integrated it into an expect-function. The password input seems to be working fine since rsync starts syncing. However, after 10-15 seconds, the syncing cancels rsync and instead directly jumps to the next step. Does anyone know what the problem might be?

The script in question follows below:

#!/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 [email protected]:/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

Upvotes: 0

Views: 332

Answers (1)

Expect has a default timeout of 10 seconds so expect eof would return after 10s. You can change the default timeout with

set timeout 300 ;# use -1 for no timeout

or use explicit timeout for each expect command:

expect -timeout 300 eof

Upvotes: 2

Related Questions