Nuclear Rooster

30Jun/113

Greppin’ with Knife

"Got tight last night on absinthe and did knife tricks." -Hemingway


Taking some inspiration from good ol' Ernest, I got tight on Tecate last night and did knife tricks. Check 'em out.

Grep remote logs across multiple machines

Tail and selectively grep logs across multiple nodes, streaming to your console:

# Look for 502's in Nginx
knife ssh 'role:load_balancer' 'tail -f /var/log/nginx/*.log | grep 502' 

# Tail the web app logs across all servers.
knife ssh 'role:web_app' 'tail -f /opt/web_app/logs/production.log' 

#

Sort nodes across a role

Get a glance at the state of servers with a particular role:

# Sort by 5min load average
knife ssh 'role:transcoder' 'cat /proc/loadavg | awk "{print $2}"' | sort -n -k 2

# Sort by uptime
knife ssh 'role:web_app' 'uptime' | sort -n -k 4

#

The other day I had the pleasure of asking Adam Jacob and Chris Brown a few questions about Chef. Chef as a tool is great, but technical changes are easier than cultural changes, since a single person can implement technical change while the entire team has to buy in to cultural change. Handing off Chef to the dev team, I had a question for Adam and Chris: "Should everybody on the team learn knife?". Their answer was "Yes." Nobody wants to learn a new tool just for the sake of it, but knife has some pretty awesome capabilities, and learning a little might go a long way.

What knife tricks do you have?

Comments (3) Trackbacks (0)
  1. knife ssh ‘platform:ubuntu’ ‘sudo apt-get -y purge puppet’

  2. Zing!

  3. A few more :) .

    Ssh to my workstations where I have chef installed under RVM and run chef-client:

    knife ssh ‘role:workstation’ ‘source .rvm/scripts/rvm && chef-client’

    Update apt cache and upgrade all my Ubuntu servers (of course I’ve already checked that the pending upgrades are safe :) ):

    knife ssh platform:ubuntu ‘sudo apt-get update && sudo apt-get upgrade -y’

    Retrieve a list of all the available search indexes:

    knife exec -E ‘p api.get(“search”).keys’


Leave a comment


Trackbacks are disabled.