#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    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:

    Code:
    grep "<strong>Date:</strong>" $1 | cut -d' ' -f3-5
    Is there an easy way to embed this logic within Ruby code - or, better yet - a way to do the same thing in Ruby?

    Thanks!
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0
    You could use system() call in Ruby. May take some tweaking to get the command right.

    example:

    Code:
    def dir_listing
    
     system("dir /o-n ")
    end
    
     dir_listing
  4. #3
  5. Web Developer/Musician
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Nov 2004
    Location
    Tennessee Mountains
    Posts
    2,408
    Rep Power
    1031
    You can also put commands in backticks as you can with PHP.

IMN logo majestic logo threadwatch logo seochat tools logo