suggestion on shell script on copy with xargs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting suggestion on shell script on copy with xargs
# 1  
Old 03-27-2009
suggestion on shell script on copy with xargs

Hi,

i am trying to copy files except the latest, my script goes here
#! /bin/bash
# to copy control files to a local DR server
# copy latest files of archive
#modified on 26-03-2009
#
--get today date
dt=` date +"%Y_%m_%d"`

--get yesterdays date
adt=`(date --date='1 day ago' +"%Y_%m_%d")`
--destination folder
dtdir=/u02/flash_recovery_area/CRM/autobackup
--source folder
cpdir=/opt/ora_central/CRM/flash_recovery_area/CRM/autobackup

--if no folder exists on todays date in destination then create folder
mkdir -p $dtdir/$dt

slg=/u02/flash_recovery_area/CRM/archivelog
clg=/opt/ora_central/CRM/flash_recovery_area/CRM/archivelog
mkdir -p $slg/$dt

--yesterday date folder found copy files if any missing from the source to destination
if [ -d $slg/$adt ]; then
find $cpdir/$adt/*.bkp -mtime 0 -exec cp -u {} $dtdir/$adt \;
find $clg/$adt/*.arc -mtime 0 -exec cp -u {} $slg/$adt \;
echo "hi"
fi

find $cpdir/$dt/*.bkp -mtime 0 -exec cp -u {} $dtdir/$dt \;
--iam trying to copy files except latest 1 file from todays date folder to target folders
find $clg/$dt/*.arc -mtime 0|sed '$d'| xargs --replace cp -u {} $slg/$dt/
eg:2009_03_26 2009-03_27

please suggest me if any changes can be made to this script to copy latest files except the last new file created from source.
# 2  
Old 03-27-2009
Quote:
Originally Posted by saha
Hi,

i am trying to copy files except the latest, my script goes here

Please put code inside [code] tags.
Quote:
Code:
#! /bin/bash
# to copy control files to a local DR server
# copy latest  files of archive
#modified on 26-03-2009 
#
--get today date


Please do not include invalid lines within your script; use comments.
Quote:
Code:
dt=` date +"%Y_%m_%d"`
 
--get yesterdays date
adt=`(date --date='1 day ago' +"%Y_%m_%d")`


Code:
adt=$(date --date='1 day ago' +"%Y_%m_%d")

Or:

Code:
adt=`date --date='1 day ago' +"%Y_%m_%d"`

Quote:
Code:
--destination folder
dtdir=/u02/flash_recovery_area/CRM/autobackup
--source folder
cpdir=/opt/ora_central/CRM/flash_recovery_area/CRM/autobackup
 
--if no folder exists on todays date in destination then create folder 
mkdir -p $dtdir/$dt
 
slg=/u02/flash_recovery_area/CRM/archivelog
clg=/opt/ora_central/CRM/flash_recovery_area/CRM/archivelog
mkdir -p $slg/$dt


Check whether the directory exists before calling mkdir:

Code:
[ -d "$slg/$dt" ] || mkdir -p $slg/$dt

Quote:
Code:
 
--yesterday date folder found copy files if any missing from the source to destination
if [ -d $slg/$adt ]; then
find $cpdir/$adt/*.bkp -mtime 0 -exec cp -u {} $dtdir/$adt \;
find $clg/$adt/*.arc -mtime 0 -exec cp -u {} $slg/$adt \;
echo "hi"
fi
 
find $cpdir/$dt/*.bkp -mtime 0 -exec cp -u {} $dtdir/$dt \; 
--iam trying to copy files except latest 1 file from todays date folder to target folders
find $clg/$dt/*.arc -mtime 0|sed '$d'| xargs --replace cp -u {} $slg/$dt/ 
eg:2009_03_26 2009-03_27

please suggest me if any changes can be made to this script to copy latest files except the last new file created from source.

I think a very similar question was asked recently. Have you searched the forum?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to copy files from on folder to another

I am trying to copy files with specific date and name to another folder. I am very new to shell scripting so i am finding it hard to do that. see the sample code i have written below. srcdir="/media/ubuntu/CA52057F5205720D/Users/st4r8_000/Desktop/office work/26 nov"... (13 Replies)
Discussion started by: Aqeel Abbas
13 Replies

2. Shell Programming and Scripting

How to copy files from one location to another using xargs??

Hello Experts, I need to copy files from one location to another using xargs. Tried something like this (In Ubuntu & Solaris ). mkdir -p 1234; find /home/emd/Desktop/n007/M007/ -type f -name "A2014*" | xargs -0 cp -r {} /home/emd/Desktop/1234 But every time i run this, a weird error... (6 Replies)
Discussion started by: Saidul
6 Replies

3. UNIX for Dummies Questions & Answers

Help with Copy Shell Script

Hello, I am currently learning UNIX scripting and have written a simple copy program. However, upon execution, it returns an error despite debugging correctly. Can anyone assist in explaining this? Attached screenshots illustrating a test execution. Many thanks. (13 Replies)
Discussion started by: dixer
13 Replies

4. Shell Programming and Scripting

need suggestion how to use the progress bar while executing shell

Dear All, I need suggestions, I have below simple text based progress-bar script which will gradually increase the %. #!/bin/ksh i=50 echo "0--------20--------40-------60--------80-------100%" while do echo -n "#" sleep 1 i=`expr $i - 1` done echo Now my problem is, how can I... (3 Replies)
Discussion started by: manas_ranjan
3 Replies

5. Shell Programming and Scripting

shell script to check permission before copy over

Hi, I am writing some shell script to check the file owner permission whether the write bit is turn on. If it is turn on it will copy the file to the destination else it will just prompt user to change the file and skipping it. However, I am starting getting loss here as I have couple of... (2 Replies)
Discussion started by: wanaka
2 Replies

6. Shell Programming and Scripting

Shell script to copy file

Dear all, I have a database with thousands of files with the structure of name is: Filename_hour_year.abc Filename_hour_year_1.abc .............. So what I need is how to write a script that all file with contain the character "_1" will copy to "_2" For example: file name:... (7 Replies)
Discussion started by: hainguyen1402
7 Replies

7. Shell Programming and Scripting

Shell Script, Copy process using find.

Ok, so here is what I am looking for.. Shell script that uses find to look for one days worth of data using the modified date and then copies only those files to a specified directory. I figured I could use grep and the find command to do this. It seems to work just fine from what I can... (4 Replies)
Discussion started by: techjunky
4 Replies

8. Shell Programming and Scripting

shell script to search and copy files

Hello Im new to this forums, I would like some help regarding a script that I need in order to copy some files. Heres the scenario: I need to search several files which have a particular code inside, lets say "test" all of them on different directories. I need to copy all of them on a new... (4 Replies)
Discussion started by: c.watson
4 Replies

9. Shell Programming and Scripting

Shell Script - Copy File at intervals

Hi, I want to copy some files from a Folder say, /usr/X at random intervals to another location. Basically, new files will be dumped at random intervals to location /usr/X and I have to copy those new files to some other location (after copying, I cannot delete those files from source... (2 Replies)
Discussion started by: angshuman_ag
2 Replies

10. Shell Programming and Scripting

How to copy and paste line in shell script

Hi I want to grep for a line and copy and paste that line. for Example ---- file abc.txt ---- host=atlx1 sid=atld1 mail=abc@abc.com host=atlx2 sid=atld2 mail=xyz@abc.com host=atlx3 sid=atld3 mail=def@abc.com host=atlx4 sid=atld4 mail=mno@abc.com --- end of file abc.txt ---- Now I... (16 Replies)
Discussion started by: upsrk
16 Replies
Login or Register to Ask a Question