一个批处理文件想转换成shell,求大神解惑
@echooff&setlocalenabledelaydexpansionset/Poldusername='Pleaseenteryourusernameforthe...
@echo off&setlocal enabledelaydexpansion
set /P oldusername='Please enter your username for the old database:'
echo Your input is:%oldusername%
set /P newusername='Please enter your username for the new database:'
echo Your input is:%newusername%
set /P newuserpassword='Please enter your password for the new database:'
echo Your input is:%newuserpassword%
set /P orcl='Please enter the oracle service name:'
echo Your input is:%orcl%
set /P syspassword='Please enter the password for sys:'
echo.
echo.
echo Moving the data,Please wait...
echo.
set str=rbtdb_16
for /f "delims=" %%i in ('dir/b script.sql')do (
(for /f "usebackq delims=" %%j in ("%%i")do (
set "a=%%j"
set "a=!a:%str%=%oldusername%!"
echo.!a!))>02_script.sql)
echo conn sys/%syspassword%@%orcl% as sysdba>01_conn.sql
echo grant select any table to %newusername%;>>01_conn.sql
echo conn %newusername%/%newuserpassword%@%orcl%>>01_conn.sql
echo exit>>01_conn.sql
sqlplus /nolog @01_conn.sql
del /q 01_conn.sql
del /q 02_script.sql
pause
@echo on&endlocal
此批处理的作用是输入新的用户名和旧的用户名,替换script.sql里的用户名,然后执行脚本,进行数据迁移,script.sql里的用户名是写死的,就是rbtdb_16.批处理将输入的旧用户名替换掉此用户名然后执行脚本。
现在想转换成shell脚本,但本人shell还没接触过,时间又比较紧,希望大神帮帮忙,谢谢
对脚本的要求是,尽量和批处理的效果一样,尽量不改变原文件即script.sql,替换完用户名后可以产生临时文件02_script.sql,执行完后最好自动删除临时文件01_conn.sql,02_script.sql。
坐等啊。。。
没人吗?急啊!!
继续等。。。 展开
set /P oldusername='Please enter your username for the old database:'
echo Your input is:%oldusername%
set /P newusername='Please enter your username for the new database:'
echo Your input is:%newusername%
set /P newuserpassword='Please enter your password for the new database:'
echo Your input is:%newuserpassword%
set /P orcl='Please enter the oracle service name:'
echo Your input is:%orcl%
set /P syspassword='Please enter the password for sys:'
echo.
echo.
echo Moving the data,Please wait...
echo.
set str=rbtdb_16
for /f "delims=" %%i in ('dir/b script.sql')do (
(for /f "usebackq delims=" %%j in ("%%i")do (
set "a=%%j"
set "a=!a:%str%=%oldusername%!"
echo.!a!))>02_script.sql)
echo conn sys/%syspassword%@%orcl% as sysdba>01_conn.sql
echo grant select any table to %newusername%;>>01_conn.sql
echo conn %newusername%/%newuserpassword%@%orcl%>>01_conn.sql
echo exit>>01_conn.sql
sqlplus /nolog @01_conn.sql
del /q 01_conn.sql
del /q 02_script.sql
pause
@echo on&endlocal
此批处理的作用是输入新的用户名和旧的用户名,替换script.sql里的用户名,然后执行脚本,进行数据迁移,script.sql里的用户名是写死的,就是rbtdb_16.批处理将输入的旧用户名替换掉此用户名然后执行脚本。
现在想转换成shell脚本,但本人shell还没接触过,时间又比较紧,希望大神帮帮忙,谢谢
对脚本的要求是,尽量和批处理的效果一样,尽量不改变原文件即script.sql,替换完用户名后可以产生临时文件02_script.sql,执行完后最好自动删除临时文件01_conn.sql,02_script.sql。
坐等啊。。。
没人吗?急啊!!
继续等。。。 展开
1个回答
展开全部
printf 'Please enter your username for the old database:'
read oldusername
echo Your input is:$oldusername
printf 'Please enter your username for the new database:'
read newusername
echo Your input is:$newusername
printf 'Please enter your password for the new database:'
read newuserpassword
echo Your input is:$newuserpassword
printf 'Please enter the oracle service name:'
read orcl
echo Your input is:$orcl
printf 'Please enter the password for sys:'
read syspassword
echo
echo
echo Moving the data,Please wait...
echo
str=rbtdb_16
sed 's/'"$str"'/'"$oldusername"'/g' script.sql >02_script.sql
echo conn sys/$syspassword@$orcl as sysdba>01_conn.sql
echo grant select any table to $newusername;>>01_conn.sql
echo conn $newusername/$newuserpassword@$orcl>>01_conn.sql
echo exit>>01_conn.sql
sqlplus --nolog @01_conn.sql
rm 01_conn.sql
rm 02_script.sql
printf "press any key to exit"
read -n 1
02_script.sql生成 后没有用又删除了是什么 意思 ?,除了sqlplus命令不知咋转换,其余的都转 换成了shell
追问
感谢,02_script.sql生成了是有用的,我贴上来的少了一句
echo conn %newusername%/%newuserpassword%@%orcl%>>01_conn.sql
echo @02_script.sql>>01_conn.sql
echo exit>>01_conn.sql
非常感谢,我明天试一试~ 分明天给你!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询