完全な開示: 私は Ruby をよく知りません。私はほとんどそれを偽造しています。
多数の Mac を管理するために使用している Casper でインベントリを収集するために使用したいスクリプトがあります。を使用して変数をシェル コマンドに渡そうとしています%x
。問題は、Ruby が変数を代わりにコメントとして扱っていることです。関連するコードは次のとおりです。
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
の代わりにバックティックを使用してみ%x
ましたが、同じ結果が得られました。このコマンドは、それが実行されているホストに関する一連の情報を返す必要がありますが、代わりに の結果を返します。dscl /Search -read /Computers
これは常にname: dsRecTypeStandard:Computers
です。
どうすればやりたいことを達成できますか?