If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > shell script to search thru a directory by passing parameter

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-19-07, 15:17
saccskiz saccskiz is offline
Registered User
 
Join Date: Feb 2004
Posts: 143
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
Reply With Quote
  #2 (permalink)  
Old 03-20-07, 05:54
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
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 08:10.
Reply With Quote
  #3 (permalink)  
Old 04-30-07, 15:08
saccskiz saccskiz is offline
Registered User
 
Join Date: Feb 2004
Posts: 143
exit 8?

Thanks..this works for me. However, I have this question: What does "exit 8" mean?
Reply With Quote
  #4 (permalink)  
Old 05-02-07, 05:51
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On