Thursday, June 26, 2008

Auto Download of Health check report CSV mail and process by Batch

To automatically download the mail, use the macro as in my case i use imacro for Firefox, you can use the imacro for internet explorer but this version has some problem with my mail server.

http://www.iopus.com/imacros/firefox/?ref=fxhome

Here's my macro, with amendments:-

VERSION BUILD=6050612 RECORDER=FX
TAB T=1
URL GOTO=http://mailbox.id
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ACTION:/?service=login&pragma=nocache ATTR=VALUE:Login
TAG POS=1 TYPE=FONT ATTR=TXT:*Report*
TAB T=2
FRAME F=2
TAG POS=1 TYPE=FONT ATTR=TXT:DailyHealthcheck.cab
'SAVEAS TYPE=CPL FOLDER=* FILE=+_{{!NOW:yyyymmdd_hhnnss}}
ONDOWNLOAD FOLDER=* FILE=+_{{!NOW:yyyymmdd_hhnnss}}
TAB T=1
FRAME F=0
BACK
WAIT SECONDS=2
TAB CLOSEALLOTHERS
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:select ATTR=NAME:tid CONTENT=YES
WAIT SECONDS=2
ONDIALOG POS=1 BUTTON=CANCEL CONTENT=
TAG POS=1 TYPE=FONT ATTR=TXT:DELETEMESSAGE
TAG POS=1 TYPE=INPUT:BUTTON FORM=NAME:NoFormName ATTR=NAME:button1&&VALUE:Return
TAG POS=1 TYPE=IMG ATTR=ALT:Refresh


My batch file looks like this, it will process each file with the cab extension , archive it and expand it to report.csv, then will bcp into database and the next command will processed the data.

for %%f in (*.cab) do copy %%f archive\%%f && expand %%f Report.csv && bcp dbaRepository.dbo.tCSV_Data in Report.csv -t, -S servername-U userid -P pwd -w -C 850 && Del %%f

rem Remember to grant execute permission to the user to execute the stored procedure

osql -S servername -U userid -P password -Q "exec dbaRepository..sp_updateCSVtables"



No comments: