shell脚本询问用户名和路径存储文件

时间:2014-03-26 05:56:08

标签: oracle unix export datapump

我需要一个shell脚本来询问用户名和pathe以将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=$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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:1)

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