Profile photo

from miller import blake

Hello, I'm a Seattle-based site reliabililty engineering manager, I get paid to do what I love, I like Python, I'm in an abusive relationship with JavaScript, I'm a fan of good design, and I don't think things always have to be so stupid.
You can follow me @bltmiller, subscribe via RSS, and email me.

Get Nginx Version With grep

It’s really easy to get the version of Nginx installed through your package manager or just from visual inspection, but there’s a small hurdle to overcome if you need to programmatically check the version when a package manager isn’t available.

For some reason, nginx -v spits out the version number to stderr, so a simple pipe will always return an exit status of 1 even if there is a match:

nginx -v | grep <version number here>

To fix this, redirect Nginx’s output from stderr to stdout and then pipe to grep:

nginx -v 2>&1 | grep <version number here>

That way, a match in grep with return an exit status of 0.

comments powered by Disqus

Copyright © 2020, Blake Miller. All rights reserved. | Sitemap · RSS