Oracle 用于询问用户名和路径存储文件的shell脚本
我需要一个shell脚本来请求用户名和路径将expdp文件存储在指定的路径中。请帮帮我。下面是我的脚本Oracle 用于询问用户名和路径存储文件的shell脚本,oracle,unix,export,datapump,Oracle,Unix,Export,Datapump,我需要一个shell脚本来请求用户名和路径将expdp文件存储在指定的路径中。请帮帮我。下面是我的脚本 #!/bin/sh STARTTIME=`date` export ORACLE_SID=test export ORACLE_HOME=`cat /etc/oratab|grep ^${ORACLE_SID}:|cut -d':' -f2` export EXPLOG=expdp_${ORACLE_SID}.log export EXPDIR=/expdir export PATH=$PA
#!/bin/sh
STARTTIME=`date`
export ORACLE_SID=test
export ORACLE_HOME=`cat /etc/oratab|grep ^${ORACLE_SID}:|cut -d':' -f2`
export EXPLOG=expdp_${ORACLE_SID}.log
export EXPDIR=/expdir
export PATH=$PATH:$ORACLE_HOME/bin
DATEFORMAT=`date +%Y%m%d`
STARTTIME=`date`
# Data Pump export
expdp system/manager content=ALL directory=expdir dumpfile=expdp_`echo $ORACLE_SID`_%U_`echo $DATEFORMAT`.dmp full=Y logfile=$EXPLOG
#expdp export/export content=ALL directory=expdir dumpfile=expdp_`echo $ORACLE_SID`_%U_`echo $DATEFORMAT`.dmp schemas=santhosha logfile=$EXPLOG
ENDTIME=`date`
/home/oracle/deleteold.sh > /backup/expdir/deleteold.log 2>&1
这将有助于:
#!/bin/bash
echo "Type the username, followed by [ENTER]:"
read usrname
echo "The name entered was: $usrname"
更新
#!/bin/bash
echo "Type the username, followed by [ENTER]:"
read usrname
echo "Type the path, followed by [ENTER]:"
read pthname
echo "The name entered was: $usrname"
echo "The path entered was: $pthname"
if [ -d "$pthname" ]
then
echo "$pthname is a directory."
expdp system/manager content=ALL directory=$pthname dumpfile=expdp_`echo $ORACLE_SID`_%U_`echo $DATEFORMAT`.dmp full=Y logfile=$EXPLOG
fi
更新2谢谢,我想保存导出路径到用户指定的路径请提供任何帮助您的意思是:
导出路径=“$path:$username”
当我运行脚本时,它应该请求路径存储导出转储,并使用该路径存储文件oh,您可以用完全相同的方式读取它:read inputpath
在oracle expdp中,我们使用在数据库中创建一个单独的目录和路径,在获取导出转储时,它使用该目录路径并将转储文件保存到该路径。现在我想将转储文件保存到用户指定的路径。您需要在没有提示的情况下自动获取?如果是,您可以使用expect
从shell提示符获取字符串。您可以向我们展示该行的工作版本,就像从命令行中键入的那样:expdp syst…expdp system/manager content=ALL directory=expdir dumpfile=expdp\code>echo$ORACLE\U SIDecho$DATEFORMAT.dmp full=Y日志文件=$EXPLOG
You can use Without Security :
echo "User name: $0"
echo "Password: $1"
You can use With Security :
read -s -p "Password: " password
$ help read
read: read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
Read a line from the standard input and split it into fields.
...
-p prompt output the string PROMPT without a trailing newline before
attempting to read
...
-s do not echo input coming from a terminal