2014-03-26 35 views
-1

我需要一個shell腳本來詢問用戶名和路徑以將expdp文件存儲在指定路徑中。請幫幫我。下面是我的腳本。請求用戶名和路徑存儲文件的shell腳本

#!/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 
+0

你需要得到自動與出來提示? – PersianGulf

+0

如果是,您可以使用'expect'從shell提示符處獲取字符串。 – PersianGulf

+0

您可以向我們展示該行的工作版本,因爲它將從行的命令行中輸入:expdp syst ... – krowe

回答

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

+0

謝謝,我想保存到用戶指定路徑的導出路徑請幫助 – user3422419

+0

您的意思是:'export PATH ='$ PATH:$ username' ' – krowe

+0

當我運行它的腳本它應該問路徑存儲出口轉儲並採取該路徑來存儲文件 – user3422419

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 
相關問題