Problems coping a file in a shl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems coping a file in a shl script
# 8  
Old 03-23-2011
@acmvillareal
I'm afraid your post contains new errors that were not in the original post and some of the errors from the original post.
One line to highlight is:
Code:
FILE_NAME=`find ${FILE_PATH}${FILE_NAME}*`

This does not match the requirement. There is only one file to copy. The statement is completely pointless.
Though not relevant here it is also a classic scripting error to dump an open-ended list of filenames into a single environment variable.

On a positive note, it does tackle the issue of the missing solidus between ${LIST_FILE_PATH} and ${FILE_NAME} by appending a solidus to ${LIST_FILE_PATH} and has also got rid of the pointless trailing semi-colon characters.


One possible source of the "[[" error message could be if the script file was edited on a Microsoft platform and then copied to a unix platform without proper conversion.

Last edited by methyl; 03-23-2011 at 11:29 PM.. Reason: layout
# 9  
Old 03-24-2011
The reason why I put that script is because you didn't put the extension file in the file name.

Code:
FILE_NAME="new_applicant_list"

# 10  
Old 03-24-2011
@acmvillareal
This is unix not MSDOS, Netware or whatever.
There is no concept of file extensions in unix bar documentary purposes. A unix file does not have to have an extension ... and in this example the single file concerned does not have an extension.

A simple example is the "ls" command. It is not "ls.exe" or "ls.com".
# 11  
Old 03-24-2011
Here is the complete script, now I am getting the following error:
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.04
Successfully executed the szpcal1.sql script
/u01/app/banner/test/links/szpcal1: [[: not found
cp: Insufficient arguments (1)
Usage: cp [-f] [-i] [-p] [-@] f1 f2
cp [-f] [-i] [-p] [-@] f1 ... fn d1
cp -r|-R [-H|-L|-P] [-f] [-i] [-p] [-@] d1 ... dn-1 dn
cp: Insufficient arguments (1)
Usage: cp [-f] [-i] [-p] [-@] f1 f2
cp [-f] [-i] [-p] [-@] f1 ... fn d1
cp -r|-R [-H|-L|-P] [-f] [-i] [-p] [-@] d1 ... dn-1 dn


Code:
 
# Set database name
SID=$ORACLE_SID;
LOWER_SID=`echo $ORACLE_SID | tr "[A-Z]" "[a-z]"`
# set banner user and password for sqlplus use
UID="xxxxx";
PW="xxxx";
USER=$BANUID;
JOBNAME="szpcal1";
JOBNUM=$ONE_UP;
AT_SIGN="@";

#----------------------------------------------------------------------------------
# Set up script specifics
MPATH=$BANNER_HOME;
SCRIPT_PATH="/u01/app/banner/test/skid/plus/";
FILE_PATH="/nfs/mercury/u03/banner/test/skid/log/";
SCRIPT_NAME="szpcal1.sql";
FILE_NAME="new_applicant_list";
#----------------------------------------------------------------------------------
# build name of job log and list file and dir path
##LOG_FILE_PATH="/u01/banjobs/TEST";
##LOG_FILE_NAME="${JOBNAME}_${USER}_${JOBNUM}.log";
LF1=${LOG_FILE_PATH}${LOG_FILE_NAME};
LF2=${LOG_FILE_PATH}${LOG_FILE_NAME};
LIST_FILE_PATH="/u01/banjobs/TEST/";
LIS_FILE_NAME="${JOBNAME}_${USER}_${JOBNUM}.lis";
LS1=${LOG_FILE_PATH}${LIS_FILE_NAME};
#----------------------------------------------------------------------------------
# write header lines to job log
echo " " >>${LF1} 2>>${LF2}
echo "SID=${SID} "  >>${LF1} 2>>${LF2}
echo " " >>${LF1} 2>>${LF2}
echo "The following are results from execution of: ${JOBNAME}.shl" >>${LF1} 2>>${LF2}
echo " " >>${LF1} 2>>${LF2}
echo "----------------------------------------------------------------- "  >>${LF1} 2>>${LF2}
echo "Start 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}
echo "----------------------------------------------------------------- "  >>${LF1} 2>>${LF2}
echo " " >>${LF1} 2>>${LF2}
#----------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------#
# change to directory where sql script is located
cd ${SCRIPT_PATH}
if test $? -eq 0
then
  echo "Successfully changed directory to run sql scripts" >>${LF1} 2>>${LF2}
  echo "${SCRIPT_PATH}" >>${LF1} 2>>${LF2}
else
  echo " " >>${LF1} 2>>${LF2}
  echo "******************************************************* "  >>${LF1} 2>>${LF2}
  echo "Error: could not change to directory "  >>${LF1} 2>>${LF2}
  echo "${SCRIPT_PATH}" >>${LF1} 2>>${LF2}
  echo " "  >>${LF1} 2>>${LF2}
  echo "No updating done. "  >>${LF1} 2>>${LF2}
  echo " "  >>${LF1} 2>>${LF2}
  echo "End Script "  >>${LF1} 2>>${LF2}
  echo "******************************************************* "  >>${LF1} 2>>${LF2}
  exit 1
fi
echo " " >>${LF1} 2>>${LF2}
echo "---------------------------------------------------------------------- " >>${LF1} 2>>${LF2}
echo "Calling SQL script " >>${LF1} 2>>${LF2}
#----------------------------------------------------------------------------------
# Run scipt to execute the PL\SQL package.
sqlplus -s ${UID}/${PW} ${AT_SIGN}${SCRIPT_PATH}${SCRIPT_NAME} ${JOBNUM} ${JOBNAME} ${USER} >>${LF1} 2>>${LF2}
sqlscript=$?
if [ $sqlscript != "0" ]
then
  echo " " >>${LF1} 2>>${LF2}
  echo "Error: could not execute the ${SCRIPT_NAME} script" >>${LF1} 2>>${LF2}
  echo " " >>${LF1} 2>>${LF2}
  echo "Script Ended" >>${LF1} 2>>${LF2}
  exit 1
else
  echo " " >>${LF1} 2>>${LF2}
  echo "Successfully executed the ${SCRIPT_NAME} script\n" >>${LF1} 2>>${LF2}
fi
#----------------------------------------------------------------------------------
## copy the output from the process to the lis file in banjobs area so it can be seen in Banner
if [[ -r ${LIST_FILE_PATH}${JOBNAME}.log ]]    #file exists and is readable
then
   echo " "  >>${LF1} 2>>${LF2}
   echo "------------------- "  >>${LF1} 2>>${LF2}
   echo "Copying output to database..." >>${LF1} 2>>${LF2}
   cp ${LIST_FILE_PATH}${JOBNAME}.log ${LS1}
   if [[ ! -r ${LS1} ]]   #file not copied to jobsub area
   then
      echo " " >>${LF1} 2>>${LF2}
      echo "Error: Report not copied to ${LS1}" >>${LF1} 2>>${LF2}
      echo " " >>${LF1} 2>>${LF2}
      echo "Script Ended" >>${LF1} 2>>${LF2}
      exit 1
   else
     ##cd ${FILE_PATH}
     ##cp ${FILE_NAME} ${LIS_FILE_PATH} ${LIS_FILE_NAME}
     echo " " >>${LF1} 2>>${LF2}
      echo "Successfully copied ${LIST_FILE_PATH}${JOBNAME}_${JOBNUM}.log to banjobs area\n" >>${LF1} 2>>${LF2}
      echo "------------------- "  >>${LF1} 2>>${LF2}
   fi
else
  cd ${FILE_PATH}
  ##FILE_NAME=`find ${FILE_PATH}${FILE_NAME}*`
  FILE_NAME=`find ${FILE_NAME}*`
  cp  ${FILE_NAME} ${LIST_FILE_NAME}
  echo "cp ${FILE_NAME} ${LIS_FILE_PATH}${LIS_FILE_NAME}" >/u01/scott/scott.tx
  ##cp ${FILE_NAME} ${LIST_FILE_PATH}${FILE_NAME}
  cp ${LIST_FILE_NAME} ${LIST_FILE_PATH}/${LIST_FILE_NAME}
#echo " " >>${LF1} 2>>${LF2}
   #echo "Error: Report created in  ${LIST_FILE_PATH}" >>${LF1} 2>>${LF2}
   #echo " " >>${LF1} 2>>${LF2}
   #echo "Script Ended" >>${LF1} 2>>${LF2}
   exit 1
fi
#-----------------------------------------------------------------
# Check for Oracle error in log file
if test `grep -l "ORA" $LF1`
then
  echo "\nOracle error found in log file." >> ${LF1} 2>>${LF2}
  exit 1
else
  echo "\nNo Oracle errors in log file." >> ${LF1} 2>>${LF2}
fi
#-----------------------------------------------------------------
# Time stamp script completion.
#====================================================================================#
echo " "  >>${LF1} 2>>${LF2}
echo "------------------------------------------- "  >>${LF1} 2>>${LF2}
echo " "  >>${LF1} 2>>${LF2}
echo "Completion Date & Time: " >>${LF1} 2>>${LF2}
date  >>${LF1} 2>>${LF2}
echo " "  >>${LF1} 2>>${LF2}
echo "SQL Completed Script" >>${LF1} 2>>${LF2}
echo "------------------------------------------- "  >>${LF1} 2>>${LF2}
echo " "  >>${LF1} 2>>${LF2}
echo "------------------- "  >>${LF1} 2>>${LF2}
echo "End of Shell Script" >>${LF1} 2>>${LF2}
echo "------------------- "  >>${LF1} 2>>${LF2}
echo " "  >>${LF1} 2>>${LF2}
exit

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ftp bash script appends to file using cron instead of coping new file

I have a bash script that is running a mysql query and creating a csv file with a time stamp. It then uploads that to a ftp server. Everything works great when I manually run it. But then I have a cron job set to run every monday, wednesday and friday at 5am est. When the cron job runs, it... (7 Replies)
Discussion started by: akallenberger
7 Replies

2. Shell Programming and Scripting

Need to decrypt a file in a directory (SHL script)

I need to decrypt a file in a directory, I need to write a shl scrip & cron job How I find the files in the directory: the file is like this: dailypayments_sfs_payment_201011151800.dat -d The decrypt command: gpg -o dailypayments_sfs_payment_201011151800.dat -d 20101115 (the date... (7 Replies)
Discussion started by: rechever
7 Replies

3. Shell Programming and Scripting

gzip and encrypted in a shl script

After I move the file to a directory, I need to gzip and encrypted. I never do this in a shl script, I do it from the command line and it works.. cd /home/nelnet spinel:/home/nelnet$ gpg -e 2010_11_07_05_11_xxxxxx_bills.dat.gz `/home/nelnet/.gnupg/gpg.conf' `/home/nelnet/.gnupg/gpg.conf'... (3 Replies)
Discussion started by: rechever
3 Replies

4. Shell Programming and Scripting

last file in a directory in a shl script

I want to capture a last file in a directory in a shl scrip Cd to the directory $last ls -1 *the_bills.dat* | tail -1 This is not problem, but I need to copy that file to another directory, but in order to be able to copy to that directory, I need to su in unix, I am sure my sistem... (2 Replies)
Discussion started by: rechever
2 Replies

5. Shell Programming and Scripting

This code works in the command line but not in a shl script

When I run this code from the command line works spinel.middlebury.edu:/u02/sct/banner/bandev2/middlebury/shl:DEV2$ ls ef* eftseq.dat spinel.middlebury.edu:/u02/sct/banner/bandev2/middlebury/shl:DEV2$ file_seq=$( < eftseq.dat) ... (1 Reply)
Discussion started by: rechever
1 Replies

6. Shell Programming and Scripting

Renaming a file use another file as a sequence calling a shl

have this shl that will FTP a file from the a directory in windows to UNIX, It get the name of the file stored in this variable $UpLoadFileName then put in the local directory LocalDir="${MPATH}/xxxxx/dat_files" that part seems to be working, but then I need to take that file and rename, I am using... (3 Replies)
Discussion started by: rechever
3 Replies

7. Shell Programming and Scripting

Reading a file (one record) in a SHL script

I am trying to read a file in a shl script (only one record) and stored in a variable file_number I got the following read -u $BANNER_HOME/xxxxxxx/misc/EFTSQL.dat file_number file_number2 = $file_number + 1 echo $file_number2 > $BANNER_HOME/xxxxxx/misc/EFTSQL.dat EOF It is not working... (2 Replies)
Discussion started by: rechever
2 Replies

8. Shell Programming and Scripting

Progress bar while coping a file needed.

Hi guys I want to create a script which will show the amount of data that is been copied from one location to another location. For example: Say i have a file called abc.img which is approximately 4 gb of size therfore everytime i copy the file from one location to another i want a progress bar... (3 Replies)
Discussion started by: pinga123
3 Replies

9. Shell Programming and Scripting

shl script capture a file

need to be able to capture a file with the following conditions: The filenames are, for example, 3526_332840.dat, where 3526 is constant, and 332840 is a sequential number which is always a couple hundred greater than the previous day's file. I want to be able to change this script to acoomplish... (1 Reply)
Discussion started by: rechever
1 Replies

10. UNIX for Dummies Questions & Answers

Having problems copying a file from a script

Hello. Complete newbie over here, and I'm hoping you can help me out with this problem. The script copies a file to a directory within my home dir. Permissions are ok and the source file exists. If I execute the cp command from the command line or hardcode the path/file name, it works. ... (6 Replies)
Discussion started by: verdugan
6 Replies
Login or Register to Ask a Question