bat,shell批量执行数据库脚本

install.bat
@echo off &setlocal enabledelayedexpansion
if exist temp rd /S/Q temp
if exist logs rd /S/Q logs
mkdir temp
mkdir logs
set type=oracle
set temp_sql=temp\temp_%type%.sql
set execute_sql=temp\execute_%type%.sql
set log_file=logs\log_%type%.txt
set str1=SQL_END
set str2=exit;

echo "Reading script,please wait..."

for /f %%i in (config\config_%type%.ini) do (
    for /f %%j in (%%i) do (             
        echo %%j>>%temp_sql%
    )   
)

copy /Y config\execute_%type%.sql temp >> %log_file%

echo "Writing script,please wait..."

for /f %%a in (%temp_sql%) do (       
    echo %%a >> %execute_sql%           
)
echo %str2% >> %execute_sql% 
echo %str1% >> %execute_sql% 

echo "Executing script,please wait..."

sqlplus /nolog @%execute_sql% >> %log_file%   

echo "Execute finish,please check logs file: %log_file%."

notepad %log_file%







install.sh
#!/bin/sh
rm -rf temp
rm -rf logs

mkdir temp
mkdir logs

temp_sql=temp/temp.sql
execute_sql=temp/execute.sql
log_file=logs/log.txt
ttisql_home=
ttisql_name=

str1=SQL_END
str2=exit

echo "Reading script,please wait..."

ttisql_home=`cat config.ini  | grep TTISQL_HOME | awk -F= '{print $2}'`
ttisql_name=`cat config.ini  | grep TTISQL_NAME | awk -F= '{print $2}'`

echo "$ttisql_home/bin/./ttisql $ttisql_name <<SQL_END"  >> $temp_sql

echo "Writing script,please wait..."

cat execute.sql >> $temp_sql

cat $temp_sql >> $execute_sql

echo $str2 >> $execute_sql
echo $str1 >> $execute_sql

echo "Executing script,please wait..."

chmod +x $execute_sql

./$execute_sql >> $log_file

echo "Execute finish,please check logs file: $log_file"

exit

你可能感兴趣的:(oracle,sql,F#,脚本,J#)