Archive for October, 2013

h1

Ruby Script to determine the Version of a CQ/AEM Instance

October 7, 2013

sometimes it’s good to get the version number of a cq instance in a script. The following is an example Ruby script that grabs the version number of your cq instance from the welcome screen

require "rubygems"
require "net/http"
require "uri"

if ARGV.length < 3
  puts "cqversion.rb username password http://localhost:4502"
else
  username = ARGV[0]
  password = ARGV[1]
  host = ARGV[2]

  uri = URI.parse(host+"/libs/cq/core/content/welcome.html")

  http = Net::HTTP.new(uri.host, uri.port)
  request = Net::HTTP::Get.new(uri.request_uri)
  request.basic_auth username, password

  response = http.request(request)

  if response.code == "200"
    puts /Version [0-9\.a-zA-Z ]*/.match(response.body)
  else
    puts "failed to get version number - http error code: ", response.code
  end
end