开发者

How to check if file exist on remote machine by scp in loop

开发者 https://www.devze.com 2023-03-23 01:33 出处:网络
How To loop this code: if scp remote-host:~/myfile ./ >& /dev/null then echo \"transfer OK\" else

How To loop this code:

if scp remote-host:~/myfile ./ >& /dev/null
then 
    echo "transfer OK"
else 
    sleep 20
fi

loop must every 20 sec check for file on remote host, if file appear loo开发者_运维知识库p have to exit.


Try:

while true
    if scp remote-host:~/myfile ./ >&/dev/null;
      then echo "transfer OK"; 
    fi
    sleep 20;
done


while true
do
    if scp remote-host:~/myfile . &> /dev/nul
    then
        echo "transfer OK"
        break
    fi
    sleep 30
done

Or, if you prefer something more compact:

while :; do 
    (scp remote-host:~/myfile . &> /dev/null) && break
    sleep 30
done
echo "transfer OK"

Note that : is a built-in null command with a zero (success) exit code.

0

精彩评论

暂无评论...
验证码 换一张
取 消