开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜