December 14th, 2012, 11:28 AM
Invoking bash from Ruby
I'm brand new to Ruby, to which I've been introduced by working with Puppet for the past 2 1/2 years. As a sys admin, I'm most comfortable working with bash, but I recognize that there are things that a scripting language can't do - like interacting with a database. So I'm writing some Ruby code to extract text out of an HTML file and then insert it into a mySQL database. I've been using Nokogiri to get some formatted text, but also need to get some text that's easy enough to get with a scripting language like bash. Specifically, I need to do this:
Is there an easy way to embed this logic within Ruby code - or, better yet - a way to do the same thing in Ruby?
grep "<strong>Date:</strong>" $1 | cut -d' ' -f3-5
You could use system() call in Ruby. May take some tweaking to get the command right.
system("dir /o-n ")
July 29th, 2013, 11:38 AM
You can also put commands in backticks as you can with PHP.