Instead of the backticks, try calling scp
with system()
. That captures scp
's exit status instead of its output. Then you can check it and retry if it was nonzero.
sleep 1 while system "scp -r user\@some_ip:/home/hbase/hourly/$datehr.tar.gz /home/hbase/hourly/$datehr.tar.gz";
This will try scp
forever at 1s intervals until success.
To limit the number of tries to 10:
my $tries = 0;
while (system "scp -r user\@some_ip:/home/hbase/hourly/$datehr.tar.gz /home/hbase/hourly/$datehr.tar.gz") {
last if $tries++ > 10;
sleep 1;
}