Chinaunix首页 | 论坛 | 博客
  • 博客访问: 287479
  • 博文数量: 73
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 452
  • 用 户 组: 普通用户
  • 注册时间: 2014-09-22 17:07
个人简介

心态决定命运

文章分类

全部博文(73)

文章存档

2017年(21)

2016年(27)

2015年(21)

2014年(4)

我的朋友

分类: Oracle

2015-01-14 11:03:56

 

目的:为应付日益繁重的数据处理开发的自助脚本

数据导出方式:sqlplus

email 方式:vb

系统环境:win2003

整个脚本分 数据导出、验证sql,导出sql, 邮件发送四个部分。

数据导出bat

echo off

echo ******************** 数据导出********************

SET db_user=******
SET db_pwd=*******
SET HOST=*******
set db_sid=***********
set shell_path=E:\AUTO\SHELL\
数据需求
set data_path=E:\AUTO\DATA
set outfile=
数据.html
set zipfile=
数据.7z

rem SET /p days=输入提取最近几天数据(默认1):
if "%days%"=="" (set days=1)

rem 验证数据量 如果数据量为0 则不导出

sqlplus @%shell_path%\check.sql %days%

echo %ERRORLEVEL%
if %errorlevel%==0 goto :end
rem
构造SQLPLUS执行脚本

echo %TIME%:开始导出数据

sqlplus   @%shell_path%\export.sql %days% %data_path%\%outfile%
echo %TIME%:
导出成功

rem 压缩数据

set path=C:\Program Files\7-Zip;%path%
set txt_file=%data_path%\%outfile%
set zip_file=%data_path%\%zipfile%

if exist %zip_file%  del %zip_file%

echo %TIME%:开始压缩%txt_file%%zip_file%
7z a %zip_file% %txt_file%
echo %TIME%:
压缩成功

if exist %txt_file% del %txt_file%

 

********************************** check.sql**********************************

SET ECHO OFF;

SET FEEDBACK OFF;

set termout OFF ;

var i number;

exec select count(*) into :i FROM TBLAE_NAME t WHERE T. DT >= &1 ;

exit :i;

********************************** export.sqll**********************************

set linesize 200

set term off verify off feedback off pagesize 999

set markup html on entmap ON spool on preformat off

SPOOL &2

 SELECT  *

  FROM  TABLE_NAME T;

  

SPOOL OFF

QUIT

********************************** SENDMAIL.VBS*******************************

'On Error Resume Next

FromAddress="****"

toAddress="*****"

CcAddress="*****"

EmailSubject="数据"

UserName="*****"

password="*****"

mailServerAddress="*****"

Dim dataContext

dataContext=""

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile("E:\AUTO\SHELL\数据需求\数据邮件正文.txt", ForReading)

Do Until objFile.AtEndOfStream

    strNextLine = objFile.ReadLine

    dataContext =dataContext+strNextLine+"
"

Loop

objFile.Close

'wscript.echo body

'wscript.echo dataContext

call SendEmail(FromAddress,ToAddress,CcAddress,EmailSubject,dataContext,UserName,Password,mailServerAddress)

Sub SendEmail(FromAdd,ToAdd,CcAdd,ssSubject,ssBody,sUserName,sPassword,smailServerAddress)

Set objEmail = CreateObject("CDO.Message")

objEmail.From = FromAdd

objEmail.To = ToAdd

objEmail.CC = CcAdd

objEmail.AddAttachment "E:\AUTO\DATA\数据.7z"

objEmail.Subject = ssSubject

objEmail.HTMLBody = ssBody

objEmail.BodyPart.CharSet = "gb2312"

'objEmail.con

objEmail.Configuration.Fields.Item _

    ("") = 2

objEmail.Configuration.Fields.Item _

    ("") = smailServerAddress

objEmail.Configuration.Fields.Item _

    ("port") = 25

      

objEmail.Configuration.Fields.Item _  

       ("") = 1

objEmail.Configuration.Fields.Item _

       ("") = sUserName

objEmail.Configuration.Fields.Item _

       ("") = sPassword

objEmail.Configuration.Fields.Update

objEmail.Send

Set objEmail=Nothing

end Sub

创建一个main.bat,配置定时任务

阅读(1480) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~