title: Chef with Ohai plugins instead bash scripting
body: <p>In Chef I need to discover all running instances. For this i have created ruby block with bash script and that is working. However i was told that this work should be done with Ohai plugins without using shell scripting. Can someone give few hints how to implement this with Ruby and Ohai plugins because i have no knowledge about this. Below you can see bash script part.</p>
  
  <pre><code>#!/bin/bash
  result=$(ps -ef|grep "mysqld"|grep -v grep|awk '{print $8}')
  if [ -z "${result}" ] ; then
    echo "no_instances"
    exit 0
  else
    OIFS=$IFS
    IFS=$'\n'
    for i in $(ps -ef|grep "mysqld"|grep -v grep);  do
      if [[ $(`echo $i|awk '{print $8}'` --version) == *"MariaDB"* ]]; then
        instance=$(echo $i|awk '{print $1}')
        getent passwd ${instance} |cut -d':' -f1
      fi
    done
    IFS=$OIFS
  fi
  </code></pre>
  
  <hr>
  
  <p>I have edited my code in ruby but I doubt that in this way i can add it under Ohai plugin. Can you suggest?</p>
  
  <pre><code>result = `ps -ef|grep "mysqld"|grep -v grep|awk '{print $1 , $8}'`
  if result and result != ""
    result.each do |line|
      cmd = `#{line.split(" ")[1].chomp + " --version\n"}`
      if cmd != "" and cmd.include? "MariaDB"
        print `getent passwd #{line.split("/")[0]} |cut -d':' -f1`
      end
    end
  else
    exit
  end
  </code></pre>
  
  <hr>
  
  <p>I tried to write Ohai plugin it would be great if someone can look into this and suggest what is wrong or how to tune it:</p>
  
  <pre><code>Ohai.plugin(:Mariadb_instances) do
  
    provides 'Mariadb_instances'
  
    collect_data(:linux) do
      Mariadb_instances Mash.new
      result = `ps -ef|grep "mysqld"|grep -v grep|awk '{print $1 , $8}'`
      if result and result != ""
        result.each do |entry|
          cmd = `#{entry.split(" ")[1].chomp + " --version\n"}`
          if cmd != "" and cmd.include? "MariaDB"
           Mariadb_instances[`hostname`] = `getent passwd #{entry.split("/")[0]} |cut -d':' -f1`  # [`hostname`] can be removed if chef provides it by default
          end
        end
      else
        Chef::Log.debug("MariaDB is not found")
      end
    end  
  end
  </code></pre>