[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ale] bash question



Greg Freemyer wrote:
> All,
>
> I'm experiencing rsync timeouts, so I want to keep invoking it
> repeatedly until it either finishes or 3 hours have gone by.  When it
> times out the return code is 30.
>
> I'm thinking this might work, but I don't have a great way to test it.
>  So could a couple bash experts review it.  I've tried it and at least
> I don't seem to have any syntax errors.
>
> Also, I tested the for loop logic with a simple sleep and it worked.
> It is the break logic I can't test easily.
>
> ===
> #!/bin/bash
>
> START=`date +%s`
> MAX_TIME='10800'   # number of seconds in 3 hours
>
> for (( DELTA=0 ; DELTA < MAX_TIME; DELTA = NOW - START))
> do
>         rsync -a
> --partial-dir=/home/forensic1000/forensic1000/transfer ... [Lots more
> args]
>         NOW=`date +%s`
>         if [ $? != 30 ]
>         then
>             break;
>         fi
> done
> ===
>
> Thanks
> Greg
>   
That looks reasonable to me, but will break on any error other than
timeout.  I would suggest comparing to 0 so you continue on any error. 
Admittedly, that could end up in an infinite loop... perhaps some sort
of max retries is in order.

David