Friday, April 11, 2014

Get IP on Linux

Today I needed to get the ip address as part of script to configure the "/etc/hosts" file. The command to get the IP is a one line command:

$ ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1 }'

Thats all it takes to get the IP address(es) of the current interfaces excluding the loop back adapter. Other variants of *nix and windows may require different commands.

Wednesday, April 9, 2014

Get rpm and dependencies

On RHEL/Centos you need to install "yum-utils" first.

$ sudo yum install yum-utils

Then you can download an rpm and its depdencies by doing the following:

$ sudo yumdownloader --resolve <rpm name>

Then, you can transport them to another computer with a USB drive.

Sunday, April 6, 2014

Add RSpec

I need to add the rspec gem to my ruby project. How do I do that?  Can I do this from the command line or do I need to open a file? Looks like I need to open my "gemspec" file and add the line:

spec.add_development_dependency "rspec"

Then, I can install the gem through bundler from the command line:

$ bundle install

Next, add a directory structure and spec files.

[project]/spec/spec_helper.rb # Reference code in ../lib
[project]/spec/[gem name]/actual_spec.rb # Relative reference to ../spec_helper.rb

Now you should be able to run rspec from the command line:

$ bundle exec rspec actual_spec.rb