Home » Infrastructure » Unix » how to use export cmd in unix script
how to use export cmd in unix script [message #193579] Mon, 18 September 2006 05:59 Go to next message
prakashrao.k
Messages: 13
Registered: September 2006
Location: BANGALORE
Junior Member

Hi,

I am trying to use export command in unix script but is not working ..explain how to do this

ex:

export ORACLE_SID=<SERVER NAME>

SERVERNAME IS enviroment
Re: how to use export cmd in unix script [message #193581 is a reply to message #193579] Mon, 18 September 2006 06:05 Go to previous messageGo to next message
Frank Naude
Messages: 4579
Registered: April 1998
Senior Member
Depending on your shell you might need to do it like this:

ORACLE_SID=<SERVER NAME>
export ORACLE_SID

Re: how to use export cmd in unix script [message #193614 is a reply to message #193581] Mon, 18 September 2006 08:23 Go to previous messageGo to next message
prakashrao.k
Messages: 13
Registered: September 2006
Location: BANGALORE
Junior Member

I tried in so many ways but nothing was working for me...Thank You Frank......thnx to orafaq
Re: how to use export cmd in unix script [message #193829 is a reply to message #193579] Tue, 19 September 2006 10:29 Go to previous messageGo to next message
gkrishn
Messages: 506
Registered: December 2005
Location: Putty a dark screen
Senior Member
ORACLE_SID and SERVER NAME are different.

You have to set database name to ORACLE_SID. SID is nothing but database name.
export ORACLE_SID=<database name>

Check all databases in ur server(Unix machine) using...
cat /etc/oratab
find your SID(database name) and export it as i said above
Re: how to use export cmd in unix script [message #196239 is a reply to message #193579] Wed, 04 October 2006 10:39 Go to previous message
BrittonLaRoche
Messages: 2
Registered: October 2006
Location: Dallas, TX
Junior Member
Here is an interactive export script I put together, works well. You can cahnge the sid to be an input parameter as well. I've attached the shell script to this post for easy download.

#!/bin/ksh
# 

#--------------------------------------------------------------
# Export Oracle database shell script
#--------------------------------------------------------------
# Description: This shell script will export the database 
#              to a compressed file with the use of a
#              named pipe for maximum efficiency.
# Notes:       1. To uncompress the file use
#              gunzip <fileName.dmp.gz>
#              2. To import the file use the oracle 
#              import utility after uncompressing.
# License:     Free for all to use in commercial products, under
#              BSD, MIT, and Apache Opensource License
#--------------------------------------------------------------
# Usage:
#--------------------------------------------------------------
# Revision information
#--------------------------------------------------------------
# Mod Date  Who / What
#--------------------------------------------------------------
# 06/20/06  Britton LaRoche, Amped Labs LLC.
#           http://www.ampedlabs.com
#           Initial Version
#
#
#
#--------------------------------------------------------------

#echo on the same line function
echon () {
    if [ X"$ECHON" = X ]
    then
    # Determine how to "echo" without newline: "echo -n"
    # or "echo ...\c"
    if [ X`echo -n` = X-n ]
    then ECHON=echo; NNL="\c"
    else ECHON="echo -n"; NNL=""
    fi

    fi
    $ECHON "$*$NNL"
}

#Cancel Message
showCancelMessage() {
    echo ""
    echo ""
    echo "-------------------------------------------------------------------"
    echo "--  Usage: exportdb.sh (export file) (userid)"
    echo "--"
    echo "-------------------------------------------------------------------"
    echo '--  Example : exportdb.sh "prod20060620.dmp" "pin" '
    echo "--"
    echo "-------------------------------------------------------------------"
    echo ""
    echo "  Process Canceled."
    echo "  Exiting Process. "
    echo ""
    exit 1
}


if [ ! -n "$ORACLE_HOME" ]; then
        echo "ORACLE_HOME is not defined"
        exit 1
fi


#--------------------------------------------------------------
#-- 2. Verify input arguments 
#--------------------------------------------------------------
#echo "Number of arguments is: $#"
#echo "The entire list of arguments is: $*"

expFile="${1}.gz"
userName="${2}"
argCount="$#"
minCount="2"


totalCount="0"
totalFiles="0"

if [ "${argCount}" -lt "${minCount}" ]; then
    showCancelMessage
fi

#-----------------------------------------------------------
#--  3. Confirm Variables
#-----------------------------------------------------------
echo ""
echo "  ------------------------------------------------------------"
echo "  ${startTime} Run Parameters: "
echo "  ------------------------------------------------------------"
echo "    Export File         :    ${expFile} (auto gzip) "
echo "    User                :    ${userName} "
echo "    ORACLE_HOME         :    ${ORACLE_HOME} "
echo "    ORACLE_SID          :    ${ORACLE_SID} "
echo "  ------------------------------------------------------------"



# Confirm parameters
echo " "
echon "  ---> Are the parameters above correct? (y/n): "
read answer   
if [ "$answer" = "y" ] || [ "$answer" = "Y" ]
    then
        # -- Start 
        echo ""
        echo "  Starting Process."
        echo ""
    else 
        showCancelMessage
        exit 1
fi

#--------------------------------------------------------------
# Begin Processing
#--------------------------------------------------------------

echon "  ---> Enter the db password for ${userName}: "
read password   

# create a named pipe
mknod exp.pipe p

# read the pipe - output to zip file in the background
gzip < exp.pipe > ${expFile} &

echo "process running: "
ps -ef | grep exp.pipe

echo " "
echo "starting export "
echo "exp BUFFER=2048 RECORDLENGTH=65536 userid=${userName}/${password} file=exp.pipe "

# feed the pipe
exp BUFFER=2048000 RECORDLENGTH=64 userid=${userName}/${password} file=exp.pipe &

echo "Exporting data: "
echo "ps -ef | grep exp "
ps -ef | grep exp

echo "Outputting to file ${expFile} ... "
echo ""



  • Attachment: exportdb.sh
    (Size: 4.19KB, Downloaded 1897 times)
Previous Topic: Relogin during shell script execution
Next Topic: Unix command doubt
Goto Forum:
  


Current Time: Sat Apr 20 05:13:29 CDT 2024