nuby: advice sought on data-slinging script

R

Roy Pardee

Hey All,

I'd like to use ruby (v1.8 on win2k) to accomplish the following:

- Connect to an instance of mssql, using
integrated security.
- Issue a sql statement & spool the results off to
a tab-delimited text file (w/a header of field names).
- RSA-encrypt that file w/a particular public key
(shell out to gpg?).
- Log into an FTP server (using particular credentials)
& put my newly-encrypted file in say, /my_folder.

I'd like this to run as a scheduled task & so would also like to do
some logging.

If I can get this together, it will be my first "production" ruby
script. I'm about midway through the pickaxe 2 book & have read all
of _why's Poignant Guide. My background is vb.net. (I've actually
got a vb.net program that does all of this, but it's clunky & I'm
trying to learn ruby, so here I am.)

I'm writing to ask for feedback on the following general approach--in
particular, are these libs my best bet?

WIN32OLE to create an ADO Connection object for
the db interaction.

WIN32OLE to create an ADO Recordset to hold the
results of my sql statement.

IO.File to create my new text file.

Iterate over the recordset's .Fields
collection, writing their names to my File.

Iterate over the recordset's .Rows collection,
writing their values to my File.

%x() to shell out to the command line w/a
proper call to gpg.

Net::FTP to log into the ftp server & move my
newly-encrypted file.

Logger to do the logging.

Are there better libs for these things? Are there alternatives to
iterating over an ADO Recordset? Is there a native encryption lib
that I can feed a gpg-generated public key to for the encryption? Any
and all advice would be most welcome.

Thanks!

-Roy
 
R

Robo

Roy said:
Are there better libs for these things? Are there alternatives to
iterating over an ADO Recordset? Is there a native encryption lib
that I can feed a gpg-generated public key to for the encryption? Any
and all advice would be most welcome.

Thanks!

-Roy

You may like to try the ruby-dbi (http://ruby-dbi.rubyforge.org/) for
accessing the database, it provides a database independent interface.
Even if you'll only be using mssql, I find the dbi more usable anyway.

After connecting to the db, you can basically create the tab delimited
file by (untested):

dbh = DBI.connect(url, user, pass)

f = File.new("dump.txt", "w+")
sql = "SELECT..."
dbh.execute(sql) do |result|
result.column_names do |col|
f.puts col.join("\t")
end

result.fetch_array do |row|
f.puts row.join("\t")
end
end
f.close
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top