Re: How to repeat a bash shell script until success
- Date: Mon, 17 Jul 2017 09:40:12 -0400
- From: cyg Simple <cygsimple@xxxxxxxxx>
- Subject: Re: How to repeat a bash shell script until success
On 7/15/2017 2:56 AM, Sorin Adrian Savu wrote:
> On Fri, Jul 14, 2017 at 4:06 PM, cyg Simple <cygsimple@xxxxxxxxx> wrote:
>> On 7/14/2017 1:27 AM, Gary Johnson wrote:
>>> On 2017-07-12, Bryan Dunphy wrote:
>>>> I have a shell script, originally created for Mac OS X. that waits
>>>> for an external drive to be mounted (by testing an “ls” of the
>>>> volume’s root directory for success) then runs an “rsync” command.
>>>> How do I get the script to be run repeatedly until successful exit
>>>> under Cygwin?
>>>> Here is the unmodified Mac OS version of the script:
>>>> if ls /Volumes/Shared >/dev/null 2>/dev/null
>>>> rsync -avz --compress-level=9 --delete-during --partial --exclude 'cache/' aleph.gutenberg.org::gutenberg /Volumes/Shared/Project-Gutenberg
>>>> exit 0
>>>> exit 1
>>> Let the name of your script be "myscript". The following will run
>>> myscript every two seconds until it succeeds.
>>> while ! myscript; do sleep 2; done
>>> This is really a bash programming question and is not specific to
>> In reality the OP script appears to be executed in a crontab system and
>> executed every X minutes. So a change to the OP question is needed
>> which is answered at. Let's remember some people have no real clue
>> as to what question they should ask and we need to interpret what is
>> being asked into what should have been asked. If interpretation isn't
>> possible then asking for a use case would be warranted.
> Actually, the correct question would be: how do I run a bash script
> when a USB stick is mounted ?
> Which is doable via Task Scheduler and a event log trigger. See
> on how to locate the appropriate event,
> As for the script:
> - don't use ls for checking file/directory presence use -f/-d (man test)
> - you will need to adjust paths (cygwin has windows drives under
> /cygdrive (cygpath -h)
And don't forget the user has the option to change /cygdrive to
something else including / which is my preference.
> On how to run the script from Task Scheduler use an action like this:
> C:\Tools\cygwin64\bin\bash.exe -c /cygdrive/c/tools/cygwin64/home/bryan/bkp.sh
> (adjust your paths accordingly )
Yes, if you don't want to run cygserver, this is another option. But if
you're moving from a *nix based system then using cron under cygserver
is what you want.
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple