Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7915877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:36:26+00:00 2026-06-03T14:36:26+00:00

Full disclosure: I don’t really know Ruby. I’m mostly faking it. I have a

  • 0

Full disclosure: I don’t really know Ruby. I’m mostly faking it.

I have a script I want to use to gather inventory in Casper, which I’m using to manage a bunch of Macs. I’m attempting to pass a variable into a shell command with %x. Problem is, Ruby is treating the variable as a comment instead. Here is the relevant code:

def get_host
 host=%x(/usr/sbin/dsconfigad -show | /usr/bin/awk '/Computer Account/ {print $4}').chomp
 raise Error, "this machine must not be bound to AD.\n try again." if host == nil
end

def get_ou
  host = get_host
  dsout = %x(/usr/bin/dscl /Search -read /Computers/#{host}).to_a
  ou = dsout.select {|item| item =~ /OU=/}.to_s.split(",")[1].to_s.gsub(/OU=/, '').chomp
end

I tried using back ticks instead of %x, but got the same result. The command should return a bunch of information about the host it’s run on, but instead it returns the result of dscl /Search -read /Computers, which is always name: dsRecTypeStandard:Computers.

How can I accomplish what I want to do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:36:27+00:00Added an answer on June 3, 2026 at 2:36 pm

    The problem is here. The Ruby always returns the last expression in a method.

    def get_host
      host=%x(/usr/sbin/dsconfigad -show | /usr/bin/awk '/Computer Account/ {print $4}').chomp
      raise Error, "this machine must not be bound to AD.\n try again." if host == nil
    end
    

    In this case, the last expression is:

    raise Error, "this machine must not be bound to AD.\n try again." if host == nil
    

    It will return the return value of raise (which don’t gonna happen actually) if host == nil or will return nil if host != nil. So your method will never return something other than nil. Replace it by:

    def get_host
      host=%x(/usr/sbin/dsconfigad -show | /usr/bin/awk '/Computer Account/ {print $4}').chomp
      raise Error, "this machine must not be bound to AD.\n try again." if host == nil
      host
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, in order to provide full disclosure, I want to point out that this
I want a ListBox full of items. Although, each item should have a different
First off, full disclosure: This is going towards a uni assignment, so I don't
I don't know that the following piece of code is really relevant, but for
Full disclosure : This is for a homework assignment. This is driving me nuts.
Full disclosure, I'm new to Visual Studio Web Tests and coding for them. I've
I have a sheet full of some raw data, about 20,000 rows and 50
We have a full text index on a fairly large table of 633,569 records.
Full code I use: $query18 = 'SELECT group_concat(id) as qc10 FROM tblorders WHERE date
Full error message: You have an error in your SQL syntax; check the manual

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.