X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; q=dns; s=default; b=ixpJ7cyPhmByQKSgq63UqlDwlLC0kQO6RpEcVfqHrxS i6ajU3StcP7tOUQ3+zoL0+7pfRpwJDKarV3eE2zRG8L9iJRAJZmGHrifT/QxPm4v XVKegudbR6CDky/+OHDNUquQh3Q+FQd18lbBkx3Of85wnuJ3J68ioSWhEGytKSA8 = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; s=default; bh=BfMbg8/qRhjZ23MJ3ea1gWTgGXY=; b=T0Adl41460FipIPI8 +2O9f9BcAIP0GVEhxyBr3++FtuZC0WKRiYMKjAuqSqpTz77HDAONMxfnD5thxPiQ xY4QPAOoQBoG+a74aWF45ULGcn88kf62ncVCN5/YfsrRAstE/29oLyzBgviECy5D 0mLDYBowWGRjzDO27GreDZlrGg= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=H*F:D*ro, U*cygsimple, sk:cygsimp, cygsimple AT gmail DOT com X-HELO: mail-vk0-f47.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-transfer-encoding; bh=aUqKBCJwODL1Ld4odrHlqbz2LYGoAx/C24GoILUpT70=; b=SEIRUMXdjhXTN2R2a67Jf0MmUVmbn+jabiX05D7QBTNBB3KLjEiSMRY9IpA72VJk9+ +00/Umg1dIEh5URNNqJaTQYX7d2r/5SCi4Dob2pyBu/UTP97ZvcoUV6GywqaKvFzvnDL qRgJuepE/p/IVvxmXPR1O80aRMNmvk0d26JmvfdJNJJ2eC1Vl+2tmpIQtEgLjhdnJFxS VXLAp3aAWr2VfG6l7UK20fwnQWWkWLGt+BIfkLFXwIW4SH5svvd6NowNRTsEWFnCu7e/ SQZQ1B+YiwEnSV2gpbMr1Gl/o7bM26E2mnwZyKz+HQdY1HlUdYTcIUZKR/6zkAalxnQh MGHw== X-Gm-Message-State: AIVw113jpA0xHM44YSW2J5coamhwCeRkuHHUJulSdxg1FifMtJovjxaN zKr3uwEbKt7Wk6PpAQvsY/QdhqRsc3myEiQ= X-Received: by 10.31.149.136 with SMTP id x130mr7590370vkd.83.1500101762014; Fri, 14 Jul 2017 23:56:02 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <8bb16934-972b-5d3e-918f-36eec3d16ca6@gmail.com> References: <97021E71-D804-42AF-8358-6276AF4514AB AT gmail DOT com> <20170714052736 DOT GA2895 AT phoenix> <8bb16934-972b-5d3e-918f-36eec3d16ca6 AT gmail DOT com> From: Sorin Adrian Savu Date: Sat, 15 Jul 2017 09:56:01 +0300 Message-ID: Subject: Re: How to repeat a bash shell script until success To: cygwin AT cygwin DOT com Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id v6F6uJmp028527 On Fri, Jul 14, 2017 at 4:06 PM, cyg Simple 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: > >> > >> #!/bin/bash > >> if ls /Volumes/Shared >/dev/null 2>/dev/null > >> then > >> rsync -avz --compress-level=9 --delete-during --partial --exclude 'cache/' aleph.gutenberg.org::gutenberg /Volumes/Shared/Project-Gutenberg > >> exit 0 > >> else > >> exit 1 > >> fi > > > > 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 > > Cygwin. > > > > 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[1]. 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. > > [1] > https://stackoverflow.com/questions/707184/how-do-you-run-a-crontab-in-cygwin-on-windows 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 https://answers.microsoft.com/en-us/windows/forum/windows_vista-windows_programs/task-scheduler-how-to-automatically-synchronize-my/45a49d83-b1d8-4d37-8896-3d2696cf9795 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) 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 ) > > > > -- > cyg Simple > > -- > Problem reports: http://cygwin.com/problems.html > FAQ: http://cygwin.com/faq/ > Documentation: http://cygwin.com/docs.html > Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple > -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple