Help in scripting

Hi All
I have a requirement to copy a file from one location to other and at the end the file copying is over it will update a oracle table with below details.

file_name
file_creation_time
copy_start_datetime
copy_end_datetime
rec_count
please help me writing this script

SOURCE_DIR=original-directory
TARGET_DIR=target-directory
if cp $SOURCE_DIR/filename $TARGET_DIR/ ; then
  echo  "update ...." | sqlplus 
fi

We'll need more detail about the table structure before we can finish the update command.

The copy command is fine.But my concern is how to get the other variables i.e source file date and time,copy start time,copy end time,size of file and word count of source file.Below is the table structure.

source_file_name varchar2(50)
source_file_creation_dime datetime
copy_start_time datetime
copy_end_time datetime
no_of_recs number(20)
file_size_bytes number(50)

How can i update the table after the copy process is over.

Deepak

What does "no_of_recs" refer to?

Co copy_start and copy_end refer to the time it took cp to start and finish?

No_of records refer to line count of the file i.e wc -l
copy_start refers to the date and time when file copy started like 01/10/2009 11:15:25 AM
copy_start refers to the date and time when file copy process is over like 01/10/2009 11:18:25 AM

Here copy took exactly 3 minutes in the above example.

I can solve some parts:

REC_CNT=`wc -l filename.txt`
FILE_SZ=`wc -c filename.txt`
START_TIME=`date +"%D %r"`
# do copy
STOP_TIME=`date +"%D %r"`

Getting the File date/time is a little more complicated. You can look at this thread for an answer, or try:

FILE_DATE_TIME=`find $PWD -name filename.txt -printf "%Tc\n"`

Hi dude
there is a command to know the file creation, access and modify

stat filename.txt

but you have to do some grep and cut operation to get the time.
since iam sending replay to ur post through windows otherwise iwould have sent the exact equation to... but by seeing the output of above cammand you will come to know what to do

FILE_DATE_TIME=`find $PWD -name filename.txt -printf "%Tc\n"`

this command is not working .. in SUN Solaris

You'll need GNU find (fileutils) for that. You can get it from SFW packages. Here's a link to an FTP site. ftp://ftp.sunfreeware.com/pub/freeware/sparc/8/fileutils-4.1-sol8-sparc-local.gz

Also, look at this thread.

Actually we don't have authority to change or install anything in the server.
If you can suggest some script that will do the activity it would be great.
The file creation time should be in the format MM/DD/YY HH:MI:SS AM format.
stat command is not even working in our unix box

Follow that thread for an example with perl. You can reduce it to a one-liner.

The hyperlink is not working..please post it again

There was another thread... I seem to have lost it.

perl -MPOSIX -e 'print strftime("%D %T",localtime((stat($ARGV[0]))[9]))."\n";' <file>

If the POSIX module isn't available, you can do the conversion "by hand", but it's more code. This gets you the mod-time.