Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Posts
    143

    Unanswered: shell script to search thru a directory by passing parameter

    I am using shell scripts to export and import data from oracle tables using expdp and impdp oracle data pump utilities.

    Having written shell scripts to do the export part, my export file names are in the format
    exp_groupn_mmddyy where
    i) groupn can be group0,group1,group2,group3 or group4 (n=0,1,2,3 or 4)
    ii) mmddyy indicates the date the export was taken

    For example, the files can be (all sitting in one directory - /usr/export )

    exp_group0_031107.dmp
    exp_group4_031507.dmp
    exp_group1_031807.dmp


    Now, in my import script, upon running the script, I would like to pass 2 parameters, the group number and
    the date. Once, a file found with the group number and the date passed, it must process that file(which was exported earlier).

    For example, if the script name is imp_data.ksh,

    If I run by passing 2 parameters like:

    imp_data.ksh group1 031807

    This script should search for the file exp_group1_031807 in the /usr/export directory and on finding it,
    should substitute a script variable called $DUMPFILE in the script with this value.

    In other words, when the script executes, exp_group1_031807.dmp will be value for $DUMPFILE


    The script I have written so far for the import is :
    -----------------------------------------------------------------
    #!/bin/ksh

    LOG_FILE=imp_`date +%m%d%y`.log

    ST=`date`

    impdb username/password@database file=$DUMPFILE log=$LOG_FILE directory=EXPORT_DIR
    fromuser=from_user_name touser=to_user_name
    tables=table1,table2 feedback=1000 buffer=20000000 ignore=y
    ET=`date`

    echo "Start Time=$ST" >>$LOG_FILE
    echo "End Time=$ET" >>$LOG_FILE

    -----------------------------------------------------------------

    Please help. Thanks

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    DUMPFILE="/usr/export/exp_${1}_${2}.dmp"
    if [ ! -f $DUMPFILE ]
    then
    echo "File $DUMPFILE does not exist"
    exit 8
    fi
    # rest of script to do load
    Last edited by pdreyer; 03-20-07 at 09:10.

  3. #3
    Join Date
    Feb 2004
    Posts
    143

    exit 8?

    Thanks..this works for me. However, I have this question: What does "exit 8" mean?

  4. #4
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Terminate the script with a return code of 8
    you can then test the return code with $? in a calling script
    e.g. after calling the script
    rc=$?
    if [ $rc -ne 0 ]
    then
    blah blah blah

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •