The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
oracle connection from shell script DILEEP410 Shell Programming and Scripting 4 07-01-2009 03:19 AM
i want to call a oracle function in my shell script dineshr85 Shell Programming and Scripting 4 10-16-2007 12:18 PM
Logging into oracle or SQL from shell script manirsendhil Shell Programming and Scripting 2 04-10-2007 12:46 AM
Shell Script for Data loading in Oracle raghuraja_r Shell Programming and Scripting 3 07-21-2006 11:00 AM
shell script- oracle connection problem nattynatty Shell Programming and Scripting 4 08-14-2002 10:48 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-26-2009
rechever rechever is offline
Registered User
  
 

Join Date: May 2009
Posts: 20
help with oracle shell script

I am getting the following error in this shl
Usage: cp [-fhipHILPU] [-r|-R] [-E{force|ignore|warn}] [--] src target
or: cp [-fhipHILPU] [-r|-R] [-E{force|ignore|warn}] [--] src1 ... srcN directory
I need to send the log file to the PRGMR_MAILING_LIST, I changed for xxxx


Code:
#! /bin/sh
#
# #Retrieves and processes CSS IDOC file, then e-mails appropriate users
#
# Created by xxxxxx, May 2009 
#
# Purpose: 
# Retrieves and processes CSS IDOC file, then e-mails appropriate users
# 
# Will be submitted from crontab. 
# 
# Directory Location:
# Database Home Dir/middlebury/shl
#
#--------------------------------------------------------------------------------
#
# Modifications:
# Date Author Description
# 
# .
#
#********************************************************************************
# Set the Database
SID="$1";
SIDQ="@${SID}";
ORAENV_ASK=NO; export ORAENV_ASK
PATH=/usr/bin:/bin:/etc:/usr/sbin:/usr/ccs/bin:/usr/ucb:$HOME/bin:/usr/bin/X11:/sbin:.:/usr/lbin:$ORACLE_HOME/bin:/usr/local/bin
export PATH
ORACLE_SID=${SID}; export ORACLE_SID; . oraenv
#waiting for account
UID_F="xxxxx";
PW_F="Dxxxxxx";
# set job name
JOBNAME1="rypidoc_shl"
# set home directory path
MPATH=$BANNER_HOME;
SCRIPT_PATH="${MPATH}/xxxxx/plus/"
SQL_SCRIPT1="@rypidoc_loadcss_run.sql"
SQL_SCRIPT2="@rypidoc_process2_run.sql"
 
# Set Log File path and name
LOG_FILE_PATH="/u02/sct/banjobs/";
LOG_FILE_NAME=${JOBNAME}_$$.log;
LF1=${LOG_FILE_PATH}${LOG_FILE_NAME};
LF2=${LOG_FILE_PATH}${LOG_FILE_NAME};
MAILING_LIST="xxxxxi@xxxxx.edu";
PRGMR_MAILING_LIST="xxxxxi@xxxxx.edu"; 
#------------------------------------------------------------------------------
# write header lines to job log
echo "${JOBNAME}.shl" >>${LF1} 2>>${LF2}
echo " " >>${LF1} 2>>${LF2}
echo "Running Date & Time: " >>${LF1} 2>>${LF2}
date >>${LF1} 2>>${LF2}
echo "Database = ${SID}" >>${LF1} 2>>${LF2}
echo " " >>${LF1} 2>>${LF2}
echo "Starting script " >>${LF1} 2>>${LF2}
echo " " >>${LF1} 2>>${LF2}
##==============================================================================##
# Capture just the file sequence number 
fseqno=`print $i | sed 's/.*_//' | sed 's/.dat//' `
cd "${MPATH}/xxxxx/dat_files"
echo $i `date` > idochd1.lst
cp $i idoc.dat
DATA_FILE="${MPATH}/xxxxx/dat_files/3526*.dat ";
#Determine if there is a file to process
ls 3526*.dat > /dev/null 2>&1 
if [ $? != 0 ] 
then 
exit
fi
for i in 3526*.dat 
do
#=================================================================================#
# Change dir to where the sql scripts are
cd ${SCRIPT_PATH}
if test $? -eq 0
then
echo " " >>${LF1} 2>>${LF2}
echo "Successfully changed dir for sql script." >>${LF1} 2>>${LF2}
echo "${SCRIPT_PATH} " >>${LF1} 2>>${LF2}
else
echo " " >>${LF1} 2>>${LF2}
echo "Error: could not change dir for sql script." >>${LF1} 2>>${LF2}
echo "${SCRIPT_PATH} " >>${LF1} 2>>${LF2}
echo " " >>${LF1} 2>>${LF2}
echo "Script Ended and no updating done." >>${LF1} 2>>${LF2}
cat ${LF1} | mailx -s "${JOBNAME1} script failed! Could not change dir for sql script" $PRGMR_MAILING_LIST 
exit 1
fi
# Run sqlplus script to Load file into tables RYRIDOC_COVER, RYRIDOC_IMAGE, RYRIDOC_TAXDATA, RYRIDOC_W2
# pass the seqno as a paramater
sqlplus -s ${UID_F}/${PW_F}${SIDQ} ${SQL_SCRIPT1} $fseqno >>${LF1} ${UID_F} 2>>${LF2}
if test $? -eq 0
then
echo " " >>${LF1} 2>>${LF2}
echo "Successfully executed the ${SQL_SCRIPT1} script\n" >>${LF1} 2>>${LF2}
egrep -i "ORA-|Aborting|Error" ${LF1} >/dev/null
error_status=$? 
if [ "$error_status" = "0" ]
then
cat ${LF1} | mailx -s "${JOBNAME1} script failed! " $PRGMR_MAILING_LIST 
echo "\nOracle error occurred. Email sent to ${PRGMR_MAILING_LIST}" >>${LF1} 2>>${LF2}
exit 1
fi 
egrep -i "00" ${DATA_FILE} >/dev/null
error_status2=$?
if [ "$error_status2" != "0" ]
then
echo "No data loaded today." >>${LF1} 2>>${LF2}
else
cat ${LF1} | mailx -s "${JOBNAME1} Loading Process Finish! Could not change dir for sql script" $PRGMR_MAILING_LIST 
echo "\nEmail sent to ${MAILING_LIST} Loading Process Finish." >>${LF1} 2>>${LF2}
fi
else
echo " " >>${LF1} 2>>${LF2}
echo "Error: could not execute the ${SQL_SCRIPT1} script" >>${LF1} 2>>${LF2}
echo " " >>${LF1} 2>>${LF2}
echo "Script Ended and no updating done." >>${LF1} 2>>${LF2}
cat ${LF1} | mailx -s "${JOBNAME1} script failed!" Could not change dir for sql script" $PRGMR_MAILING_LIST 
exit 1
fi
#===================================================================================#
# Change dir to where the sql scripts are to run script2
cd ${SCRIPT_PATH}
if test $? -eq 0
then
echo " " >>${LF1} 2>>${LF2}
echo "Successfully changed dir for sql script." >>${LF1} 2>>${LF2}
echo "${SCRIPT_PATH} " >>${LF1} 2>>${LF2}
else
echo " " >>${LF1} 2>>${LF2}
echo "Error: could not change dir for sql script." >>${LF1} 2>>${LF2}
echo "${SCRIPT_PATH} " >>${LF1} 2>>${LF2}
echo " " >>${LF1} 2>>${LF2}
echo "Script Ended and no updating done." >>${LF1} 2>>${LF2}
cat ${LF1} | mailx -s "${JOBNAME1} script2 failed!" Could not change dir for sql script" $PRGMR_MAILING_LIST 
exit 1
fi
# run scipt to do the processing
sqlplus ${UID_F}/${PW_F} ${SQL_SCRIPT2} >>${LF1} 2>>${LF2} 
if test $? -eq 0
then
echo " " >>${LF1} 2>>${LF2}
echo "Successfully executed the ${SQL_SCRIPT1} script\n" >>${LF1} 2>>${LF2}
egrep -i "ORA-|Aborting|Error" ${LF1} >/dev/null
error_status=$? 
if [ "$error_status" = "0" ]
then
cat ${LF1} | mailx -s "${JOBNAME1} script2 failed!" Could not change dir for sql script" $PRGMR_MAILING_LIST 
echo "\nOracle error occurred. Email sent to ${PRGMR_MAILING_LIST}" >>${LF1} 2>>${LF2}
exit 1
fi 
egrep -i "00" ${DATA_FILE} >/dev/null
error_status2=$?
if [ "$error_status2" != "0" ]
then
echo "No data loaded today." >>${LF1} 2>>${LF2}
else
cat ${LF1} | mailx -s "${JOBNAME1} data loaded today !" Could not change dir for sql script" $PRGMR_MAILING_LIST 
echo "\nEmail sent to ${MAILING_LIST} Loading Process Finish." >>${LF1} 2>>${LF2}
fi
else
echo " " >>${LF1} 2>>${LF2}
echo "Error: could not execute the ${SQL_SCRIPT1} script" >>${LF1} 2>>${LF2}
echo " " >>${LF1} 2>>${LF2}
echo "Script Ended and no updating done." >>${LF1} 2>>${LF2}
cat ${LF1} | mailx -s "${JOBNAME1} script1 failed!" Could not change dir for sql script" $PRGMR_MAILING_LIST 
exit 1
fi
#-----------------------------------
echo " " >>${LF1} 2>>${LF2}
echo " " >>${LF1} 2>>${LF2}
echo "End Date & Time: " >>${LF1} 2>>${LF2}
date >>${LF1} 2>>${LF2}
echo " " >>${LF1} 2>>${LF2}
echo "Shell Script Completed." >>${LF1} 2>>${LF2}
exit

Bits Awarded / Charged to rechever for this Post
Date User Comment Amount
05-26-2009 Neo Added code tags for poster. -5,000
  #2 (permalink)  
Old 05-26-2009
cambridge cambridge is offline
Registered User
  
 

Join Date: May 2009
Posts: 55
It looks to me like your problem is with this line:


Code:
cp $i idoc.dat

You haven't set the 'i' variable by this point, it is empty, hence the error from the 'cp' command - which expects two arguments. You don't set 'i' until a few lines later:


Code:
for i in 3526*.dat

  #3 (permalink)  
Old 05-26-2009
rechever rechever is offline
Registered User
  
 

Join Date: May 2009
Posts: 20
Sorry still don't get it, new at this stuff
when I have the shl like this one, it worked, it is only when I try to code to send emails,


Code:
#!/bin/ksh
#Retrieves and processes CSS IDOC file, then e-mails appropriate users

set -x

SID="$1";
SIDQ="@${SID}";

ORAENV_ASK=NO; export ORAENV_ASK
PATH=/usr/bin:/bin:/etc:/usr/sbin:/usr/ccs/bin:/usr/ucb:$HOME/bin:/usr/bin/X11:/sbin:.:/usr/lbin:$ORACLE_HOME/bin:/usr/local/bin
export PATH
ORACLE_SID=${SID}; export ORACLE_SID; . oraenv

#waiting for account
UID_F="xxxxxx";
PW_F="xxxx";

# set job name
JOBNAME="rypidoc_shl"
# set home directory path
MPATH=$BANNER_HOME;

SCRIPT_PATH="${MPATH}/xxxxx/plus/"
SQL_SCRIPT1="@rypidoc_loadcss_run.sql"
SQL_SCRIPT2="@rypidoc_process2_run.sql"

#rm idochd1.lst htfn1.file htfn2.file  2> /dev/null

#Section One - Download from Website

#Section Two - Identify file(s) to process, process and rename

cd "${MPATH}/xxxxx/dat_files"

#Determine if there is a file to process
ls 3526*.dat > /dev/null 2>&1 

if [ $? != 0 ]                
then 
  exit
fi

for i in 3526*.dat              
do


# Capture just the file sequence number 
fseqno=`print $i | sed 's/.*_//' | sed 's/.dat//' `

cd "${MPATH}/xxxx/dat_files"
echo $i   `date` > idochd1.lst

cp $i idoc.dat

# Load file into tables RYRIDOC_COVER, RYRIDOC_IMAGE, RYRIDOC_TAXDATA, RYRIDOC_W2
##cd $SOFTPATH/script
# Change dir to where the sql scripts are
cd ${SCRIPT_PATH}
sqlplus -s ${UID_F}/${PW_F}${SIDQ} ${SQL_SCRIPT1}  $fseqno  >>${LF1} ${UID_F} 2>>${LF2}

# Process 
##cd $SOFTPATH/script
###sqlplus / @$SOFTPATH/script/rypidoc_process2_run.sql
cd ${SCRIPT_PATH}
sqlplus ${UID_F}/${PW_F} ${SQL_SCRIPT2}  >>${LF1} 2>>${LF2}

##cd $SOFTPATH/data/finaid/idoc
cd "${MPATH}/xxxxx/dat_files"

mv $i $i.processed

#Notify User
##cd $SOFTPATH/bin
##asysmail idoc.mail "CSS IDOC file received and processed" $SOFTPATH/log/rypidoc_process2.log
 echo "\nEmail sent to ${MAILING_LIST} Loading Process Finish." >>${LF1} 2>>${LF2}

# Find the last error file for each type
tfn1=$( ls -1t ${MPATH}/xxxxx/dat_files/idoc_nomatch* | grep -v BAN1bat| head -1 )

#Determine if tfn1 has any records-if so, send

count=`cat $tfn1 | wc -l `

if [ $count != 0 ]
then
cat ${MPATH}/xxxxx/dat_files/idochd1.lst $tfn1 > ${MPATH}/xxxx/dat_files/htfn1.file
##asysmail idoc.mail "CSS IDOC-No Match File" $SOFTPATH/data/finaid/idoc/htfn1.file
fi

tfn2=$( ls -1t $${MPATH}/xxxx/dat_files/idoc_error* | grep -v BAN1bat| head -1 )

#Determine if tfn2 has any records-if so, send

count=`cat $tfn2 | wc -l `

if [ $count != 0 ]
then
cat $${MPATH}/xxxx/dat_files/idochd1.lst $tfn2 > $S${MPATH}/xxxxx/dat_files/htfn2.file
##cd $SOFTPATH/bin
###asysmail idoc.mail "CSS IDOC-Error File" $SOFTPATH/data/finaid/idoc/htfn2.file
fi

done

exit

Bits Awarded / Charged to rechever for this Post
Date User Comment Amount
05-26-2009 Neo Added code tags for poster. -5,000
  #4 (permalink)  
Old 05-28-2009
cambridge cambridge is offline
Registered User
  
 

Join Date: May 2009
Posts: 55
Quote:
Sorry still don't get it, new at this stuff
when I have the shl like this one, it worked, it is only when I try to code to send emails,

Code:
echo $i `date` > idochd1.lst
cp $i idoc.dat
.....
for i in 3526*.dat 
do
...
done

...does not work because $i is not set when you are outside the for loop.


Code:
for i in 3526*.dat              
do
...
echo $i   `date` > idochd1.lst
cp $i idoc.dat
...
done

...works because your references to $i come inside the for loop (between the do and done).

This is basic shell stuff, I suggest you buy a book on UNIX shell scripting and work through some examples.
  #5 (permalink)  
Old 05-28-2009
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
A variable should be set before you can use it to do some operation which it doen't expect a null string
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:47 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0