Hello… I’m new to ruby, but love the style that things are done.
I’ve programmed before but never with anything involving databases, so
I’m a bit lost on what do to with this. Basically, I’m trying to pass a
query to a db2 database and then have it return the results. I am unable
to do this however. Every time I run my script it says, “ruby.exe -
System error The program can’t start because DB2CLI.dll is missing from
your computer. Try reinstalling the program to fix this problem.” I’ve
followed the instructions for installing the gems I needed based on what
I’ve seen on the net, but I really have no clue where to start on this.
My reason for creating the application is to query and print out
information on a user from 4 different servers.
After commenting out the code involving db2, I seem to be getting errors
with really ANY “required” gem though. For instance, using highline to
block out password works fine in irb and works fine if I call it like
“ruby -r rubygems UserInfo.db” but it doesn’t work if I just run it
through aptana. Is my installation of ruby/aptana/git/etc… broken, or
is this just some stupid novice mistake I’ve made. ^^;;
Here is the code and also the os/ruby version.
INFORMATION:
Windows7 Pro 64-bit
ruby 1.9.3p194 (2012-04-20) [i386-mingw32]
git version 1.7.11.msysgit.1
Aptana Studio 3, build: 3.2.2.201208201020
USERINFO.RB:
require ‘rubygems’
require ‘net/ssh’
require ‘mswin32/ibm_db’
require ‘highline/import’
#Functions for ssh and db query
def ssh_exec_return(hostname,username,password,cmd)
begin
ssh = Net::SSH.start(hostname, username, :password => password)
out = ssh.exec!(cmd)
ssh.close
puts out
rescue
puts “Unable to connect to #{hostname}! Maybe check your
username/password?”
end
return res
end
#db query func
def run_select_query(query,host,username,password,dbname)
connection = nil
begin
connection = IBM_DB.connect(“DRIVER={IBM DB2 JDBC
DRIVER};DATABASE=#{dbname};HOSTNAME=#{host};PORT=50004;PROTOCOL=TCPIP;UID=#{username};PWD=#{password;}”,
“”, “”)
rescue IBM_DB::DatabaseError => e
puts “An error occurred”
puts “Error code: #{e.err}”
puts “Error message: #{e.errstr}”
end
dataset = IBM_DB.exec(connection,query).fetch_all
connection.disconnect
return dataset
end
puts “This utility will output LME and Intraweb permissions, as well as
output which distribution lists a user is a member of. Just a few
questions
first though.”
puts “What is the users uid?”
@UID = gets.chomp
puts “What is the Users email?”
@EMAIL = gets.chomp
puts “What is the root password”
@ROOT_PASS = ask(“=>”) { |q| q.echo = false }
puts “What is your username?”
@ADMIN_USER = gets.chomp
puts “What is your Password?”
@ADMIN_PASS = ask(“=>”){ |q| q.echo = false }
puts “ALRIGHT! The Information will now be queried”
puts “----LME USER PERMISSIONS----”
run_select_query(“select * from group_membership where
user_id=‘#{@UID}’”,“server.mycompany.com”,“#{@ADMIN_PASS}”,“#{@ADMIN_USER}”,“mydb”)
puts “----User Login.bat Contents----”
ssh_exec_return(“Server.mycompany.com”,“#{@ADMIN_UID}”,“#{@ADMIN_PASS}”,“cat
/share/netlogin/#{@UID}.bat”)
puts “----Zimbra User Email Groups----”
ssh_exec_return(“mailserver.mycompany”,“root”,“#{ROOT_PASSWORD}”,“zimbra
zmprov gam #{@EMAIL}”)
I’m sure you’ll find a lot of mistakes in what I’m doing. ^^;; But this
is one of those things that is stupidly long to do manually when it
could be done pragmatically… I’m a help desk person and the programmers
have higher priority things to achieve. ^^;;;