Reputation: 5983
I'm trying to download from remote last N directories using following script:
echo "Downloading last $lastN failed tests..."
RECENT=$(ssh $USER@$IP ls -1td $DIR/* | head -$lastN)
scp -r $USER@$IP:"$RECENT" $TARGET
but it downloads only first file and throws errors for others:
bash: line 1: /some/path/test_2018-12-08-20-21-19: Is a directory
bash: line 2: /some/path/test_2018-12-07-15-08-53: Is a directory
bash: line 3: /some/path/test_2018-12-07-14-56-28: Is a directory
bash: line 4: /some/path/test_2018-12-07-14-54-12: Is a directory
What's wrong with my script?
Upvotes: 0
Views: 1730
Reputation: 4487
First you need to iterate on all values of $RECENT variable, instead of specifying it at once to the scp command.
for recentElement in $RECENT; do
scp -r $USER@$IP:"$recentElement " "$TARGET/"
done
But, you may need to adapt the way you create the $TARGET
variable, are you sure it is a directory?
Did you consider using rsync
, instead of scp
?
Upvotes: 1