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
    Create a CSS Cube

    CSS cubes really showcase what CSS has become over the years, evolving from simple color and dimension directives to a language capable of creating deep, creative visuals.  Add animation and you've got something really neat.  Unfortunately each CSS cube tutorial I've read is a bit...

  • By
    Conquering Impostor Syndrome

    Two years ago I documented my struggles with Imposter Syndrome and the response was immense.  I received messages of support and commiseration from new web developers, veteran engineers, and even persons of all experience levels in other professions.  I've even caught myself reading the post...

Incredible Demos

  • By
    MooTools Fun with Fx.Shake

    Adding movement to your website is a great way to attract attention to specific elements that you want users to notice. Of course you could use Flash or an animated GIF to achieve the movement effect but graphics can be difficult to maintain. Enter...

  • By
    Introducing MooTools HeatMap

    It's often interesting to think about where on a given element, whether it be the page, an image, or a static DIV, your users are clicking.  With that curiosity in mind, I've created HeatMap: a MooTools class that allows you to detect, load, save, and...

Discussion

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