-1

i need a shell script to ask the username and pathe to store the expdp file in a specified path. please help me. below is my script.

#!/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
user3422419
  • 21
  • 1
  • 10

2 Answers2

1

This should help:

#!/bin/bash

echo "Type the username, followed by [ENTER]:"

read usrname

echo "The name entered was: $usrname"

Update

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

Update 2

krowe
  • 2,129
  • 17
  • 19
  • thanks, i want to save to export path to user specified path pls any help – user3422419 Mar 26 '14 at 06:07
  • Do you mean: `export PATH='$PATH:$username'` – krowe Mar 26 '14 at 06:13
  • when i run the script it shoud ask path to store export dump and take that path to store files – user3422419 Mar 26 '14 at 06:15
  • Ohh, you can read that in the exact same way: `read inputpath` – krowe Mar 26 '14 at 06:16
  • in oracle expdp we used create a seperate directory with path in database itself, while taking export dump it uses that directory path and saves dump file to that path. now i want to save my dump file to the path which user has specified. – user3422419 Mar 26 '14 at 06:27
  • I'm not understanding what the problem is. – krowe Mar 26 '14 at 06:32
  • i want to save oracle export dump file the path which we specify at the starting time, means when we run script it shoud ask path and take that path to store dump files; – user3422419 Mar 26 '14 at 06:40
  • @user3422419 Gave it another shot – krowe Mar 26 '14 at 06:44
  • No am correct, while exporting oracle will use a directory which we have created in rdbms i.e create directory directory name as '/ptah', my question is i dont want to save export dump in this directory instead of it should save it in the path which we have specified. – user3422419 Mar 26 '14 at 06:51
  • I'm guessing that is what the `directory=$pthname` part should fix. – krowe Mar 26 '14 at 06:52
  • Export: Release 11.2.0.3.0 - Production on Wed Mar 26 12:24:06 2014 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options ORA-39002: invalid operation ORA-39070: Unable to open the log file. ORA-39087: directory name /BACKUP/ is invalid – user3422419 Mar 26 '14 at 06:56
  • Is /BACKUP/ the directory you entered? If it is then this is working just not finished. You need to create the directory and setup the permissions. – krowe Mar 26 '14 at 06:57
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
Ayyappa Boligala
  • 1,096
  • 7
  • 7