-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservers.rb
More file actions
executable file
·54 lines (48 loc) · 1.3 KB
/
servers.rb
File metadata and controls
executable file
·54 lines (48 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/ruby
require "dbi"
require "parseconfig"
class Servers
attr_reader :all
def initialize
myConfig = ParseConfig.new("../las.conf")
mysqlHost = myConfig.get_value("mysqlHost")
mysqlUser = myConfig.get_value("mysqlUser")
mysqlPass = myConfig.get_value("mysqlPass")
database = myConfig.get_value("database")
begin
@dbh = DBI.connect('DBI:Mysql:' + database + ':' + mysqlHost + ':3306', mysqlUser, mysqlPass)
row = @dbh.select_one("SELECT VERSION()")
print "\nConnected to #{database}:servers\n"
rescue DBI::DatabaseError => e
puts "An error occured"
puts "Error code : #{e.err}"
puts "Error message : #{e.errstr}"
end
sql = "SELECT * FROM servers"
begin
sth = @dbh.prepare(sql)
sth.execute()
result = sth.fetch_all
sth.finish
@all = result
p @all
rescue DBI::DatabaseError => e
print "\nSELECT failed in #{self}\n"
print "\n", e.err, "\n", e.errstr, "\n"
rescue
print "SELECT failed in #{self}\n"
print "\nNot a DBI error\n"
print "\n", $!
end
begin
@dbh.disconnect
rescue DBI::DatabaseError => e
print "\nClose @dbh failed in #{self}\n"
print "\n", e.err, "\n", e.errstr, "\n"
rescue
print "Close @dbh failed in #{self}\n"
print "\nNot a DBI error\n"
print "\n", $!
end
end
end