issue while copying file dynamically whith in loop?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting issue while copying file dynamically whith in loop?
# 1  
Old 03-15-2012
issue while copying file dynamically whith in loop?

I need to copy the log file dynamically and that should run in loop , which means it should pick what ever the latest file is updated in that directory.

I am able to display the list and copy to directly but i have no idea on how to pick the dynamically updated files.

when i use this code, i am getting the output for single time.


Code:
find . -newer ./latestfile.log  -print | cpio -pvdmu /export/home/myhome/data_temp/

here i am hard coding the latest file: latestfile.log , how can i pick it automatically?
# 2  
Old 03-15-2012
Use your own temporary file to do that.

Code:
touch /tmp/flagfile
find . -newer /path/to/flagfile | ...
touch --reference=/tmp/flagfile /path/to/flagfile
rm /tmp/flagfile

Note how the timestamp is actually updated before you run find, but not actually used until after. This is intentional, in case files were added during that run of find, to make sure they're not skipped for having an "older" timestamp.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print loop output on same line dynamically

Hi, I am trying to print copy percentage completion dynamically by using the script below, #!/bin/bash dest_size=0 orig_size=`du -sk $sourcefile | awk '{print $1}'` while ; do dest_size=`du -sk $destfile | awk '{print $1}'` coyp_percentage=`echo "scale=2; $dest_size*100/$orig_size"... (4 Replies)
Discussion started by: Sumanthsv
4 Replies

2. Shell Programming and Scripting

Issue in Concatenation/Joining of lines in a dynamically generated file

Hi, I have a file containing many records delimited by pipe (|). Each record should contain 17 columnns/fields. there are some fields having fields less than 17.So i am extracting those records to a file using the below command awk 'BEGIN {FS="|"} NF !=17 {print}' feedfile.txt... (8 Replies)
Discussion started by: TomG
8 Replies

3. Shell Programming and Scripting

Issue with copying files into dir inside for loop

Hi , I'm trying to move/copy the files inside the loop into a directory . I tried the below code and the issue is the data is not copying into the created directory but the files are copying into another file file_path="/home/etc" Last_Day=20130930 mkdir $file_path/ARC_${Last_Day} ... (3 Replies)
Discussion started by: smile689
3 Replies

4. Shell Programming and Scripting

Issue with copying files

Hi I have to write a shell script which copy files from one folder to another. When I try to do it directly from command prompt cp filename.dat /outgoing/filename.dat its working fine. But when I put the same command inside a shell script say test.sh its not getting copied. and when I check $?... (3 Replies)
Discussion started by: ravinunna
3 Replies

5. UNIX for Dummies Questions & Answers

File copying in FOR loop

Hi, I am trying to perform a dos2unix conversion for a file. I am doing this in the FOR loop. Below is the command I am using in my script. $FILE is the file the for loop is processing currently and I would like to convert $FILE and create a $FILE_I dos2unix -n $WORK/$FILE $WORK/$FILE_I... (3 Replies)
Discussion started by: Vijay81
3 Replies

6. UNIX for Dummies Questions & Answers

Copying files with spaces in the filename in a for loop

Hi all, I've been tangoing with this one for a couple of days now and I'm still not making any progress. Basically I'm trying to match three numbers in a string from a text file with matching numbers in a jpeg, and then copying the results to another folder. Data looks like this: Model:... (4 Replies)
Discussion started by: faceonline
4 Replies

7. UNIX for Dummies Questions & Answers

Saving file edited whith sed

HI! I have a file that looks like this: >ANKRD30_2kb AAGTAACCAATGCAGGAAACCGAGAGGAGAGGTTTGGAAGGTGGTTTAGTGAGGTAATCCATCTTTTCT AGTGATAAACTGGCACCCAGTCAATTTATTCATCAGAAGGGAATACATCAGCCTGGCGTGGTGGCTCGC CCCCGACCCTGTCAGCGTCACCAGCAGCGCGGATCCATGGGCCAGAAGCCTCTAGGGCGCCTAAGTCAG Number of residues in the... (9 Replies)
Discussion started by: vanesa1230
9 Replies

8. Shell Programming and Scripting

Adding string variable dynamically in for loop

Hi, I need to generate the text name dynamically in for loop, ex, VAR_COPY_FILE1= file path 1 VAR_COPY_FILE2= file path 2 VAR_COPY_FILE3= file path 3 for i in 1 2 3 do if then "do some process here" fi done (3 Replies)
Discussion started by: msubash26
3 Replies

9. UNIX for Dummies Questions & Answers

Permissions issue after copying files

Hi everyone, I am using mac os x 10.6, and I just copied over a project from a machine with 10.5... And I noticed my ls color is very funky in this directory... I found that my permissions are all messed up, and am wondering if there is a way to recursively fix permissions? This is how they... (3 Replies)
Discussion started by: patrick99e99
3 Replies
Login or Register to Ask a Question