Skip to content

Instantly share code, notes, and snippets.

@mmdemirbas
Created October 8, 2012 13:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmdemirbas/3852550 to your computer and use it in GitHub Desktop.
Save mmdemirbas/3852550 to your computer and use it in GitHub Desktop.
Batch script to execute a given command repeatedly. Waits specified amount of time between two executions.
@echo off
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: This script executes given command repeatedly.
:: Waits specified amount of time between two executions.
:: First parameter MUST be sleep time.
:: Rest of the parameters will be executed as a command.
:: This script relies on sleep command from GnuWin32 package.
::
:: usage: (1 minute = 60 seconds intervals. More info: sleep --help)
:: listen 60 grep -w needle "haystack.txt"
:: listen 60s grep -w needle "haystack.txt"
:: listen 1m grep -w needle "haystack.txt"
::
:: @author: mmdemirbas@gmail.com
::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: First argument is expected to be sleep time
set SLEEP_TIME=%1
:: Other arguments will be a command with or without some parameter(s)
set command=
:init
shift
if [%1]==[] goto exec
set command=%command% %1
goto init
:exec
call %command%
sleep %SLEEP_TIME%
goto exec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment