Skip to content

Keep trying a command every X minutes, and stop after Y minutes have passed, or the command succeeds Raw

Notifications You must be signed in to change notification settings

mikecharles/keep-trying

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 

Repository files navigation

keep-trying

The keep-trying command executes a given command every X minutes, and stops after Y minutes, or when the command succeeds. It's useful for trying to run a command that, for example, uses input data that may or may not be available yet.

This script assumes the command passes or fails based on the exit status of the command, so if you're running your own script as the command, make sure it exits with the proper exit status (0 for success, anything else for failure).

Installing

Clone the repo:

$ git clone https://github.com/mikecharles/keep-trying.git

Install:

$ make install

This will install the keep-trying script in ~/bin (it will create the ~/bin directory if it doesn't already exist).

Examples

Run ~/bin/myscript.sh every 5 minutes for an hour

$ keep-trying -i 5 -t 60 ~/bin/myscript.sh

Run ~/bin/myscript.sh every 5 minutes for an hour, including command line options, and email [email protected] if there was an error:

$ keep-trying -i 5 -t 60 -e [email protected] ~/bin/myscript.sh opt1 opt2

Run ~/bin/myscript.sh every 5 minutes for an hour, including command line options, redirect all output to a log file, and email [email protected] the log file if there was an error:

$ keep-trying -i 5 -t 60 -e [email protected] -l ~/myscript.log ~/bin/myscript.sh opt1 opt2

Run ~/bin/myscript.sh every 5 minutes for an hour and email [email protected] a message about the failure, including a custom email subject:

$ keep-trying -i 5 -t 60 -e [email protected] -s "Something bad happened..." ~/bin/myscript.sh

About

Keep trying a command every X minutes, and stop after Y minutes have passed, or the command succeeds Raw

Resources

Stars

Watchers

Forks

Packages

No packages published