Command Line Polling

By  on  

In an ideal world, we wouldn't have to poll for anything; we would always have events to trigger other functions.  This isn't an ideal world, however, so it's important to know how to poll in multiple programming languages.  I've covered JavaScript polling (with and without Promises), but what about command line polling?  For example, ensuring MYSQL is up before attempting to perform more operations.

Here's the basic syntax:

# while ! (command here); do
while ! mysql -uroot; do
  sleep 1
done

The example above performs the mysql -uroot operation (which will fail until mysqld is up) every second.  Keep in mind the poll operation you run should be as simple as possible, just enough to know that what you want to use is available!

Recent Features

  • By
    Regular Expressions for the Rest of Us

    Sooner or later you'll run across a regular expression. With their cryptic syntax, confusing documentation and massive learning curve, most developers settle for copying and pasting them from StackOverflow and hoping they work. But what if you could decode regular expressions and harness their power? In...

  • By
    LightFace:  Facebook Lightbox for MooTools

    One of the web components I've always loved has been Facebook's modal dialog.  This "lightbox" isn't like others:  no dark overlay, no obnoxious animating to size, and it doesn't try to do "too much."  With Facebook's dialog in mind, I've created LightFace:  a Facebook lightbox...

Incredible Demos

  • By
    Shake Things Up Using jQuery UI’s Shake Effect

    Yesterday I created a tutorial showing you how you can shake an element using Fx.Shake, a MooTools component written by Aaron Newton. It turns out that jQuery UI also has a shake effect which can draw attention to an element. The XHTML Exactly the same as...

  • By
    Scroll IFRAMEs on iOS

    For the longest time, developers were frustrated by elements with overflow not being scrollable within the page of iOS Safari.  For my blog it was particularly frustrating because I display my demos in sandboxed IFRAMEs on top of the article itself, so as to not affect my site's...

Discussion

    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!