Script for incremental file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for incremental file
# 1  
Old 01-14-2010
Bug Script for incremental file

Hi ,

I have incremental file FILE1 which locate in directory /asd/ This directory contains log files whose name entries goes in FILE1

how to make shell scripts for following condition

shell script executes on

day1
FILE1 entry ---->
1.log
2.log
3.log
4.log

script read 4.log Checks if exist in /xyz/
If "Yes" then exit
If "No" the cp -r /asd/4.log /xyz/

day2
FILE1 entry -------->
1.log
2.log
3.log
4.log
5.log

script read 5.log Checks if exist in /xyz/
If "Yes" then exit
If "No" then cp -r /asd/5.log /xyz/

script read 4. log Checks if exist in /xyz/
If "Yes" then exit
If "No" then cp -r /asd/4.log /xyz/

Thanks
# 2  
Old 01-14-2010
try this one
Code:
 
for i in `cat FILE1 ` ; do if [ ! -f /xyz/$i ]; then cp $i /xyz/$i ; fi  ; done

Code:
 
for i in `cat FILE1 ` ; do if [ ! -f /xyz/$i ]; then cp /asd/$i /xyz/$i ; fi  ; done

This User Gave Thanks to xoops For This Post:
# 3  
Old 01-16-2010
Bug

Quote:
Originally Posted by xoops
try this one
Code:
 
for i in `cat FILE1 ` ; do if [ ! -f /xyz/$i ]; then cp $i /xyz/$i ; fi  ; done

Code:
 
for i in `cat FILE1 ` ; do if [ ! -f /xyz/$i ]; then cp /asd/$i /xyz/$i ; fi  ; done


I made following scripts but when second time execute this query it copying the new file and in last shows such error "7.log.gz already exists; do you wish to overwrite (y or n)? n" what changes to be done in script that it copies only new file after it exits from loop

Code:
#!/bin/bash

awk '{ a[NR]=$0 } END { for(i=NR; i; --i) print a[i] } ' /home/bin/FILE1 > /home/bin/FILE2 // this command will reverse the order latest first
sleep 1
echo "Today is $(date)"
echo "--------------------"

for i in `cat /home/bin/FILE2`;
do
  if [ ! -f /home/xyz/$i ];
  then cp -r  /home/bin/$i /home/xyz/$i ;
    gzip -9  /home/xyz/$i
    echo "Copying binlogs : $i"
  else
    exit 0
  fi  ;
done
exit 0


Last edited by Franklin52; 01-16-2010 at 09:32 AM.. Reason: Please indent your code and use code tags!!
# 4  
Old 01-16-2010
Hi.

By "copies only new files", do you mean only if the file does not already exist?

You could change your cp command to something like:
Code:
false | cp -ifr  /home/bin/$i /home/xyz/$i 2> /dev/null

That's the same as if your cp has the -n option, then:
Code:
cp -nr  /home/bin/$i /home/xyz/$i

If you meant "update files" without being asked, change it to:
Code:
cp -fr  /home/bin/$i /home/xyz/$i

Not sure what you mean by "after it exits from loop"?

Last edited by Scott; 01-17-2010 at 07:49 AM..
This User Gave Thanks to Scott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Incremental extract from growing log file.

We have a log file which has 16 million row. We want to read all the lines appended from the last time we read using sed command sed -n '<START_LINE>,<LAST_LINE>p' abc.csv I can store this last line line so I can give replace that with START_LINE in my next read. The problem is wc -l which... (2 Replies)
Discussion started by: one2connect
2 Replies

2. Shell Programming and Scripting

Incremental numbering?

Would it be possible for a script to duplicate a file and incrementally number it? File in: XXX_007_0580_xxxx_v0016.aep File out: XXX_007_0580_xxxx_v0017.aep If someone knows of a way I'd love to see it. Thanks! (7 Replies)
Discussion started by: scribling
7 Replies

3. Shell Programming and Scripting

FULL or INCREMENTAL ???

Hi. Can someone tell me if the following script that i have made is a script for INCREMENTAL BACKUP or FULL BACKUP. My teacher told me that is doing an FULL BACKUP. • find /etc /var /home -newer /backups/.backup_reference > /backups/.files_to_archive • touch /backups/.backup_reference • tar... (1 Reply)
Discussion started by: bender-alex
1 Replies

4. Shell Programming and Scripting

Using awk to append incremental numbers to the end of duplicate file names.

I'm currently working on a script that extracts files from a .zip, runs an sha1sum against them and then uses awk to pre-format them into zomething more readable thusly: Z 69 89e013b0d8aa2f9a79fcec4f2d71c6a469222c07 File1 Z 69 6c3aea28ce22b495e68e022a1578204a9de908ed File2 Z 69... (5 Replies)
Discussion started by: Ethereal
5 Replies

5. Shell Programming and Scripting

Shell Script Incremental

I have a master sequence say >Seq ATGCGTA....... That I want to repeat N no of times and each time the sequence is the same but the header changes in incremental numerical order E.g. >Seq1 ATGCGTA....... >Seq2 ATGCGTA....... >Seq3 ATGCGTA....... . . . . >SeqN ATGCGTA....... (3 Replies)
Discussion started by: pcg
3 Replies

6. Windows & DOS: Issues & Discussions

Incremental Backup

I have a folder /root/test in a centos 5.3 system. I want to take an incremental backup of the contents of the folder in the C:\Downloads folder of a windows system present in the same lan as the linux system. What are the ways of executing this plan? Kindly help (0 Replies)
Discussion started by: proactiveaditya
0 Replies

7. UNIX for Dummies Questions & Answers

incremental by 1

let says, i have this number as 000002080, i want to add 1 to make it 000002081, and then i want to add 1 to 000002082, add 1 to 000002083, 84. i=000002080 TOT=$(echo "scale=9; $i + 1" | bc) echo $TOT it shows 2081, i want to retain 000002081, 000002082, 000002082, 000002084. (2 Replies)
Discussion started by: tjmannonline
2 Replies

8. Shell Programming and Scripting

[bash] Simple backup (cp) script but incremental

Hi all, I would need a rather simple bash backup script that loops throught the (local) users and for each users backs up (cp!) its /home/username folder. About the functionalities: The script has to run every 2 hours (that's cron, so don't mind about that) and the files should be copied to... (12 Replies)
Discussion started by: laurens
12 Replies

9. UNIX for Dummies Questions & Answers

incremental backup

Hi All.. i am trying to write a script which will give the incremental tar backup of all files with latest timestam. i tried with find -mmin -2 but if it takes half on hour or something to creat the tar itself, then no meaning in using the above command. so please help me to find the... (2 Replies)
Discussion started by: Usha Shastri
2 Replies
Login or Register to Ask a Question