Copy command does not work


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy command does not work
# 1  
Old 02-19-2015
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 :
Code:
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.
Code:
> 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 fileSmilie
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?

Moderator's Comments:
Mod Comment Thread moved. Please post in the correct forum ...

Last edited by rbatte1; 02-19-2015 at 01:42 PM..
# 2  
Old 02-19-2015
I don't understand the code.
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?
# 3  
Old 02-19-2015
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.
# 4  
Old 02-19-2015
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?
# 5  
Old 02-19-2015
steps you provided aren't quite matching up

Good day. You originally posted:
Code:
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.

Last edited by Scrutinizer; 02-19-2015 at 11:56 AM.. Reason: Changed code tags to code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Shell copy command don't work

I want copy Files: But cp don't work: shell_exec("cp ".$pfad." ".$genzone); shell_exec("cp ../Chrysanthemum.jpg ../test"); Whats wrong? (3 Replies)
Discussion started by: Linuxmann
3 Replies

2. UNIX for Dummies Questions & Answers

grep command does not work

Hello. I have a question as to why my grep command does not seem to be working. grep -c '^?*' ~ grep -c '^.*' ~ I wanted to count the number of files starting with the letter K and have some letters after that. I have such files in my home directory. However, the output is 0. So, I have no... (2 Replies)
Discussion started by: FUTURE_EINSTEIN
2 Replies

3. UNIX for Dummies Questions & Answers

copy *. does not work in function

Hi, I want to copy a file/directory ( recursively , if needed) and if destination directory does not exist create it ( with parent directory, if needed). funcopy () { if ; then echo "$2 exists , copying files" cp -r "$1" "$2" else echo "Directory does not exist;Create directory" mkdir... (1 Reply)
Discussion started by: greet_sed
1 Replies

4. Shell Programming and Scripting

command does not work

need help, trying make a command where the user presses any keys and it will go to the home page, however it doesnt work, why ? echo -p "press any key to return to main menu" menu if ]; then echo -p "\n" home fi (5 Replies)
Discussion started by: bassmasta1
5 Replies

5. Shell Programming and Scripting

scp : recursive copy doesn't work

Hi I have a problem with scp command : I try to copy a list of files from source to destination, it works fine but if there is a directory not existing on destination, it doesn't automatic create. Syntax : scp -rp /<PATH>/<NEW_DIR>/<FILE> <USER_DEST>@<HOST_DEST>:<PATH>/<NEW_DIR>/<FILE>... (5 Replies)
Discussion started by: madmat
5 Replies

6. UNIX for Dummies Questions & Answers

Copy a command string from the command line

How can we copy a command string from a previous command line and paste it into the cursor position on the current command line? I know that ^c will not work as the shell will interpret as an interrupt signal. Thanks, (1 Reply)
Discussion started by: Pouchie1
1 Replies

7. Shell Programming and Scripting

How to make copy work faster

I am trying to copy a folder which contains a list of C executables. It takes 2 mins for completion,where as the entire script takes only 3 more minutes for other process. Is there a way to copy the folder faster so that the performance of the script will improve? (2 Replies)
Discussion started by: prasperl
2 Replies

8. UNIX for Dummies Questions & Answers

at command does not work

at command does not work with graphic programs like firefox, evolution, etc It works with other commands for example: at now shutdown -h now OK but at now firefox does not work Anyone knows if its possible to open a firefox window at a scheduled time? Thanks Jose (0 Replies)
Discussion started by: otilesoj
0 Replies

9. UNIX for Dummies Questions & Answers

Command work but not in SH script

Command works but not in SH At terminal if i type: scp test.tar.gz user1@server2:/home/user Everything run smoothly (keyed, no password need) At script , test.sh #!/bin/sh scp test.tar.gz user1@server2:/home/user Nothing happen and clue ? ? ? ? ? (3 Replies)
Discussion started by: cititester
3 Replies

10. HP-UX

ls command doesnt work

Good Day I mistakely renamed the dld.sl file in the /usr/lib directory. When i try to ls/ftp into the box i get this error :eek: crt0: ERROR couldn't open /usr/lib/dld.sl errno:000000002 I have tried to rename it back from the renamed file to the original file name, but it gives me the... (2 Replies)
Discussion started by: shawnbishop
2 Replies
Login or Register to Ask a Question