Chinaunix首页 | 论坛 | 博客
  • 博客访问: 51804
  • 博文数量: 13
  • 博客积分: 1465
  • 博客等级: 上尉
  • 技术积分: 130
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-01 10:15
文章分类

全部博文(13)

文章存档

2011年(2)

2008年(11)

我的朋友

分类: Sybase

2008-11-10 14:53:12

 
 
 
生成批量执行SQL的bat脚本(Perl)
 
 
@filetype = ('\.sql', '\.sp', '\.qry', '\.trg');
opendir('filedir', '.');
@files = readdir('filedir');
foreach $filename (@files) {  #check file extensions for match
 if (-d $filename) {next}
 $listpos = 0;
 until ($listpos > $#filetype) {
  if ($filename =~ m/$filetype[$listpos]/i) {
   push (@scripts, $filename)  #insert matches in array
  }#end if
  $listpos += 1;
 }#end until
}#end foreach
$count = 0;
$total = $#scripts +1;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
print "rem Loading Scripts Generated ",$mon+1,"/$mday/",$year+1900," $hour:$min:$sec\n";
print "echo off \n";
print "echo .................................................................. \n";
print "echo usage proc.bat username password servername databasename \n";
print "echo .................................................................. \n\n";
print "date /T >PROCS_%4.OUT \n";
print "time /T >>PROCS_%4.OUT \n\n";
print "if \"%1\"==\"\" goto USAGE \n";
print "if \"%2\"==\"\" goto USAGE \n";
print "if \"%3\"==\"\" goto USAGE \n";
print "if \"%4\"==\"\" goto USAGE \n\n";
print "echo Running BUILD_RELEASE_NUMBER scripts... \n\n";
foreach $scriptname (@scripts) {  #print array contents
 printf "echo %3d of%3d START LOAD: \U$scriptname \E >> PROCS_\"%4\".OUT\n",$count+=1,$total;
 printf "echo %3d of%3d START LOAD: \U$scriptname \E \n",$count,$total;
 print "echo Creating Temp Script... started \n";
 print "if NOT \"%4\" == \"\" echo USE %4  > TempSQL.SQL \n";
 print "if NOT \"%4\" == \"\" echo GO     >> TempSQL.SQL \n";
 print "type \"\U$scriptname\E\"   >> TempSQL.SQL \n";
 print "echo Running Script... \U$scriptname  \n";
 print "isql -U%1 -P%2 -S%3 -JUTF8 -iTempSQL.SQL >> PROCS_\"%4\".OUT\n";
 printf "echo %3d of%3d END LOAD: \U$scriptname \E \n",$count,$total;
 printf "echo %3d of%3d END LOAD: \U$scriptname \E >> PROCS_\"%4\".OUT\n\n",$count,$total;
}#end foreach
print "del TempSQL.SQL \n\n";
print "echo Finished. \n\n";
print "date /T >>PROCS_%4.OUT \n";
print "time /T >>PROCS_%4.OUT \n\n";
print "EXIT /B \n\n";
print ":USAGE \n";
print "echo ERROR ENCOUNTERED ! \n";
print "echo PLEASE FOLLOW CORRECT SYNTAX AS SHOWN BELOW : \n";
print "echo %0 username password servername databasename \n\n";
阅读(2917) | 评论(0) | 转发(0) |
0

上一篇:Auto generate BCP In/Out file(Perl)

下一篇:Practice

给主人留下些什么吧!~~