nubs.narf.io: pipe output from the command line to a URL

Preface

STFU lemme see: http://nubs.narf.io/

Background

Recently I’ve been working on combining two large baseball databases and wanted to be able to easily view the output of this long running process by just going to a URL on my phone.

I knew I could use the SSH client on my phone to attach to the tmux session on my desktop, but thought that something like a live-updating Github Gist would be much cooler.

Implementation

I wanted a command line utility that I could use like…

$ ./bb --dir ~/rs | nubs http://nubs.narf.io/o/bb20130719

…where “bb” is the long running process that writes to STDOUT and “nubs” is the command line client sending STDOUT off to be displayed in the browser.

This command line client should not spit any of its output to STDOUT and instead output the data that was piped into it, incase I wanted to redirect that output somewhere else. I wanted to be able to just go to the URL given as the argument to this command line client and see STDOUT in my browser.

The web app had to display output from that process to all browser clients that connected. The pages it served should also load quickly (the largest page, assets included is just a bit larger than 100KB total…I’d recently watched this great talk fwiw).

The code for the command line client is up at https://github.com/natlownes/nubs-cli.

I plan on making a binary client available for download so one doesn’t have to have node.js and npm installed.

I think I’m going to clean up the backend code before releasing it. It uses Express and the websocket library SockJS.

Deployment

I wanted to be able to run several backend processes behind haproxy and any requests to the same URL had to be sent to the same backend process. This is necessary since each process maintains its own collection of client connections. A ‘balance uri depth 2’ on the haproxy frontend config was used to do this.

The backend service is run with the awesome runit, and it’s all configured with a few Chef cookbooks, which I’ll probably release and discuss in a future post since I couldn’t find the equivalent of an “application_connect” or “application_node” cookbook.

Potential Uses

  • You want to view output of a log in real time with a bunch of remote people simultaneously.
  • You want to barbeque but you also want to view the output of some process you’re running elsewhere.
  • You work on a project that has inconsistent test failures and want to quickly show a remote colleague all like, “Fucking hell. Watch this: Do you get this too, in this random order, like bottled and distilled fucking madness?”
  • You want to send someone a link to http://nubs.narf.io/o/HollerAtThisDopeFuckingFaceRightHere, tell them to “HANDLE IT”, while you’re running something like while sleep 10 ; do cat ~/.xface | nubs http://nubs.narf.io/o/HollerAtThisDopeFuckingFaceRightHere ; done

Limitations, Disclaimers, Annoyances, and Pleas

  • Disclaimer: This was hacked together in a few days and might bite you, or me, or everyone. Or it might turn out to be a terrible idea.
  • Limitation: If your process finishes before you hit your URL in the browser, you won’t see any output. I’m thinking of fixing this by saving the last 10 or so lines for a limited time.
  • Annoyance: The JS code in the browser scrolls down to the bottom of the page when it receives data. This could be annoying but for my use case continually scrolling down manually was more annoying.
  • Annoyance: ANSI colors don’t display correctly.
  • Limitation/Annoyance: Command line and browser clients won’t detect a disconnect and attempt to reconnect.
  • Annoyance: Display in the browser when someone connects to the associated socket.
  • Disclaimer: There’s no concept of ownership or privacy with these URLs; if two people/processes are piping output to the same URL, the merged output will be displayed. So you could be innocently tailing some log and then be forced to look at an ascii cock real quick. Furthermore, that ascii cock and your logs won’t even be encrypted at any point in its journey to your eyeballs.
  • TOS: By using this service, you agree to Be Reasonable. If you are the type of person who a tool like this would interest, you can almost certainly think of ways to abuse it. So hey, just please don’t do that. I’m just a person.
  • Pleas: Pleas(e) contact me if you want to talk about this.

If you want to use it

$ npm install -g nubs-cli

…and then go to nubs.narf.io to get a URL to pipe to. Or just make one up, like http://nubs.narf.io/o/honk.