早教吧作业答案频道 -->其他-->
一个批处理文件想转换成shell,@echooff&setlocalenabledelaydexpansionset/Poldusername='Pleaseenteryourusernamefortheolddatabase:'echoYourinputis:%oldusername%set/Pnewusername='Pleaseenteryourusernameforthenewdatabase:'e
题目详情
一个批处理文件想转换成shell,
@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"
\x05set "a=!a:%str%=%oldusername%!"
\x05echo.))>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.
坐等啊.
继续等.
@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"
\x05set "a=!a:%str%=%oldusername%!"
\x05echo.))>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.
坐等啊.
继续等.
▼优质解答
答案和解析
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
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
看了 一个批处理文件想转换成she...的网友还看了以下:
母亲只为别人着想,不为自己着想用一成语形容 2020-04-11 …
对有才有徳的人以礼想让,一成语 2020-04-11 …
一边看一边想打一成语,有时候问一下打一词语 2020-06-05 …
熟话说,头痛治头,脚痛治脚,现想用一成语表达,什么成语好呢?还有就是与之意思相反的成语又是什么? 2020-06-20 …
不怕劳苦,不怕埋怨,形容一心为公的好思想猜一成语 2020-06-20 …
目前已知最大的鲸约有十六万公斤重,我想到?一成语 2020-07-06 …
著名科学家杨振宁从立志写实验物理论文改为理论物理的研究。从此,踏上成为物理学界一代杰出的理论大师之路 2020-11-15 …
在第21届冬奥会上,我国花样滑冰老将申雪、赵宏博夺得了金牌,20多年的执着追求终于如愿以偿。这启示我 2020-12-08 …
“理想是明灯,照亮我们前进的路;理想是号角,激励我们勇往直前”。这句话告诉我们()A.理想是一成不变 2020-12-15 …
对薄公堂,气急败坏,可孜借鉴,冥思苦想,打一成语 2020-12-19 …