DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Michael has posted 7 posts at DZone. View Full User Profile

Just #@$% Do It!

12.04.2006
| 2414 views |
  • submit to reddit
        If you have an unreliable network feed and want to run something like rsync, scp, etc. without having to babysit it a simple function can be used to prefix a command.  The function looks like this:

# Function to force a command to try until it works.
# Name means "JUST #@$% DO IT!"
JFDI () {
  COMMAND=$*
  while ! $COMMAND ; do echo "Retrying..." ; done
}

Using it is simplicity itself:

# command that can fail and annoy
rsync -avz /my/local/directory/ myuser@host:~/my/remote/directory/

# command that won't give up ever
JFDI rsync -avz /my/local/directory/ myuser@host:~/my/remote/directory/