Never been to DZone Snippets before?

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

Just #@$% do it! (See related posts)

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:

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


Using it is simplicity itself:

   1  
   2  # command that can fail and annoy
   3  rsync -avz /my/local/directory/ myuser@host:~/my/remote/directory/
   4  
   5  # command that won't give up ever
   6  JFDI rsync -avz /my/local/directory/ myuser@host:~/my/remote/directory/

You need to create an account or log in to post comments to this site.


Click here to browse all 5545 code snippets

Related Posts