Copy command does not work

I am new to this forum. I have a script which randomly throws error.Following are steps followed in this script:

  1. Generate Term file
  2. Remove previous term and rpt files from utility directory.
  3. copy term file to utility directory
  4. call sql to generate rpt file using term file as input
  5. copy the generated rpt file from run directory to utility directory.

I get error from sql as :

ORA-29283 - Invalid file operation.

This happens when term file is not present in utility directory when sql is called.

Code snippet is shown below. Please ignore the syntax error, if any.

> RUN_DIR/nj.terms
if [[ -s RUN_DIR/nj.terms ]] then
rm -f /utl/nj.terms
rm -f /utl/nj.rpt
cp RUN_DIR/nj.terms utl

/bin/sqlplus USER PSWD @sql

cp utl/nj.RPT RUN_DIR

fi

After script runs, if we check utility directory we can find term file:confused:
This error occurs randomly. Is there any chance system takes more time to copy the Term file to Utility directory and before completing the copy command, sql started running?

I don't understand the code.

> RUN_DIR/nj.terms                  # truncate the file to zero size
if [[ -s RUN_DIR/nj.terms ]] then   # if the file exists and it is not zero size, then ...

So the if the file is always made zero prior to the if statement, then the if statement will not get executed?

Am sorry. I did not include the code showing how nj.terms is created. My code is in remote desktop and hence i can not copy it here. nj.terms has data which is formatted like:
plan|hic|date.

Since nj.terms has contents, if condition is satisfied and run the following commands to remove and copy the files.

Could it be due to you removing files from absolute paths but copy to/from relative paths? So results depend on what your $PWD is?

Good day. You originally posted:

1. Generate Term file
2. Remove previous term and rpt files from utility directory.
3. copy term file to utility directory
4. call sql to generate rpt file using term file as input
5. copy the generated rpt file from run directory to utility directory.

However, you commands contradict your steps. For example, step #5 says to copy the generated SQL file from run directory to the utility directory. Yet, the copy command [CODE][cp utl/nj.RPT RUN_DIR/CODE] is contradicting that.

Additionally, you are dealing with relative paths instead of absolute paths (as previously point ed out) and there doesn't seem to be any error checking in case one of your steps fail (such as a rm or cp command).

You are also using references to /util in some lines and util/ in others... one being an absolute path, whilst the other is a relative path. Not to mention, are there two seperate files nj.rpt and nj.RPT ?

I would suggest you use absolute paths for starters. Additionally, the ; may be required after the ]] in your if then statement. Additionally, the RUN_DIR... is this a directory, or supposed to be a variable ?

If you fix up your variables and use absolute paths, that should rememdy your situation.