NAME
repeat - Repeat a command a number of times
VERSION
This document describes version 0.006 of repeat (from Perl distribution App-repeat), released on 2024-12-10.
SYNOPSIS
Usage:
% repeat [REPEAT OPTIONS] -- [PROGRAM] [PROGRAM OPTIONS ...]
% 2x [REPEAT OPTIONS] -- [PROGRAM] [PROGRAM OPTIONS ...]
% 3x [REPEAT OPTIONS] -- [PROGRAM] [PROGRAM OPTIONS ...]
% 4x [REPEAT OPTIONS] -- [PROGRAM] [PROGRAM OPTIONS ...]
% 5x [REPEAT OPTIONS] -- [PROGRAM] [PROGRAM OPTIONS ...]
Below are some examples.
This will run somecmd
10 times:
% repeat -n10 -- somecmd --cmdopt
This will run somecmd
10 times with a delay of 2 seconds in between:
% repeat -n10 -d2 -- somecmd --cmdopt
This will repeatedly run somecmd
until tomorrow at 10am with a delay of between 2 and 10 seconds in between (keywords: jitter):
% repeat --until-time 'tomorrow at 10AM' --delay-min=2 --delay-max=10 -- somecmd --cmdopt
This will run somecmd
10 times with exponentially increasing delay from 1, 2, 4, and so on:
% repeat -n10 --delay-strategy=Exponential=initial_delay,1 -- somecmd --cmdopt
Dry-run mode and show debugging messages: do not actually run the command, just show it in the log (require Log::ger::Screen).
% TRACE=1 PERL5OPT=-MLog::ger::Screen repeat -n10 --dry-run -- foo
DESCRIPTION
repeat
is a CLI utility that lets you repeat running a command a number of times. In its most basic usage, it simplifies this shell construct:
% for i in `seq 1 10`; do somecmd --cmdopt; done
into:
% repeat -n10 -- somecmd --cmdopt
You can either specify a fixed number of times to repeat (-n
) or until a certain point of time (--until-time
) with an optional maximum number of repetition (--max
).
Delay between command can be specified as a fixed number of seconds (--delay
) or a random range of seconds (--delay-min
, --delay-max
) or using a backoff strategy (see Algorithm::Backoff).
You can opt to bail immediately after a failure (--until-fail
) or after a success (--until-success
).
OPTIONS
--help, -h, -?
-n
Uint. Number of times to run the command. Alternatively, you can use
--until-time
(with optional--max
) instead.--until-time
String representation of time. Will be parsed using DateTime::Format::Natural. Alternatively, you can use
-n
instead.Note that dependency to DateTime::Format::Natural is declared optionally (RuntimeSuggests). You need to install the module first if you want to use
--until-time
.--max
Uint. When
--until-time
is specified, specify maximum number of repetition.--delay, -d
Float. Number of seconds to delay between running a command. Alternatively, you can specify
--delay-min
and--delay-max
, or--delay-strategy
.--delay-min
Float.
--delay-max
Float.
--delay-strategy
Str. Pick a backoff strategy from Algorithm::Backoff. It should be a module name under
Algorithm::Backoff::
namespace, without the prefix, optionally followed by,
(or=
) and a comma-separated list of arguments. For example:Exponential=initial_delay,1,max_delay,10
Note that the failure delay values are used as the delays.
Also note that the dependency is not specified explicitly; you have to install it yourself.
--until-fail
Bool. Stop repeating as soon as exit code of command is non-zero (failure). Alternatively, you can specify
--until-success
instead.--dry-run
Dry-run mode. Don't actually run the command, just show it in the log. But delays will be performed; use
--dry-run-delay
to skip delaying also.--dry-run-delay
Dry-run mode for delay. Don't actually delay, just show it in the log.
ENVIRONMENT
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/App-repeat.
SOURCE
Source repository is at https://github.com/perlancar/perl-App-repeat.
SEE ALSO
norepeat from App::norepeat.
retry from App::AlgorithmBackoffUtils.
AUTHOR
perlancar <perlancar@cpan.org>
CONTRIBUTING
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.
COPYRIGHT AND LICENSE
This software is copyright (c) 2024 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-repeat
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.