Skip to content

Instantly share code, notes, and snippets.

@shoaibi
Created June 25, 2015 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shoaibi/e42b2ab4f6f2754293f3 to your computer and use it in GitHub Desktop.
Save shoaibi/e42b2ab4f6f2754293f3 to your computer and use it in GitHub Desktop.
Keep retrying some job till it executes successfully
#!/bin/bash
# Keep retrying some job till it executes successfully
#
# I primarily use this script to download files from servers
# that break the connection after certain minutes. Combining
# this with aria2c makes a really awesome sure-fire way to
# download your files.
#
carryOutJob()
{
DONE=30
job="$1"
until [ $DONE -eq 0 ]; do
echo "starting: $job"
$job
DONE=$(echo $?)
# You may add some sleep over here
done
}
E_BADARGS=65
echo
if [ $# -ne 1 ]
then
echo "Usage: $0 {job}"
exit $E_BADARGS
fi
carryOutJob "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment