NAME

repeat - Repeat a command a number of times

VERSION

This document describes version 0.001 of repeat (from Perl distribution App-repeat), released on 2024-12-06.

SYNOPSIS

Usage:

% repeat [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 'tomorrow 10AM' --delay-min=2 --delay-max=10 -- somecmd --cmdopt

(NOT YET IMPLEMENTED) 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

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) 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 (NOT YET IMPLEMENTED) using a backoff strategy (see Algorithm::Backoff).

You can opt to bail immediately after a failure (--bail).

OPTIONS

  • -n

    Uint. Number of times to run the command. Alternatively, you can use --until (with optional --max) instead.

  • --until

    String representation of time. Will be parsed using DateTime::Format::Natural. Alternatively, you can use -n instead.

  • --max

    Uint. When --until is specified, specify maximum number of repetition.

  • --delay

    Float. Number of seconds to delay between running a command. Alternatively, you can specify --delay-min and --delay-max, or (NOT YET IMPLEMENTED) --delay-strategy.

  • --delay-min

    Float.

  • --delay-max

    Float.

  • --delay-strategy

    Str. NOT YET IMPLEMENTED.

  • --bail

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.

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.