生成批量执行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) |