How to move gz files from one source directory to destination directory?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to move gz files from one source directory to destination directory?
# 8  
Old 04-04-2016
oops!!!!

Now the script is working properly. But how to amend in the log files that means i want to know how many files were moved out to source to destination.
# 9  
Old 04-04-2016
Hi,

Ok, can I ask you to just humor me here and tack the following to the end of the find statement as follows.

Code:
find . -name "*.gz" -mtime +1 -print -exec mv {} /var/opt/projects/apps/ \; > list.txt

And send me the output of the following;

Code:
cat list.txt

Followed by;

Code:
wc -l list.txt

When I run the command locally all seems to be OK for me;

Code:
-bash-3.2$ find bin/ -type f -mtime +10 -print -exec cp {} tmp/ \; > tfile.txt
-bash-3.2$ cat tfile.txt
bin/getpinglist.sh
bin/logger.sh
bin/template_snap.sh
bin/working
bin/SP_Template.sh
bin/estate_check.sh
bin/details.sh
bin/w_details.sh
bin/test.sh
bin/net_search.sh
bin/sshchpass.exp
bin/alive_list.sh
bin/qd_script.sh
bin/os-s-checkconfig
bin/delete_me.txt
-bash-3.2$ wc -l tfile.txt
      15 tfile.txt
-bash-3.2$

Regards

Gull04
# 10  
Old 04-04-2016
Hi ,

I have amended in to log file . It is working perfectly. But i observed the files are moving to different path which it seems the script is not working as expected.

Code:
#!/usr/bin/bash
echo "Finding files that are 90+ days old in the server.  Output will be a list of files to be moved:"

if find /var/opt/projects/apps/. -name "*.gz" -mtime +1 -print -exec echo  mv {} /var/opt/projects/apps/temp/ \; >file1.txt
then    echo 'Script completed successfully.'
else    echo 'One or more errors are reported above.'
        exit 2
fi

O/p

Code:
mv /var/opt/projects/apps/./temp/tmp0.39455717678172897.gz /var/opt/projects/apps/temp/
/var/opt/projects/apps/./temp/tmp0.42892912234008185.gz


Last edited by Don Cragun; 04-04-2016 at 04:55 PM.. Reason: Add CODE tags.
# 11  
Old 04-06-2016
Please suggest me
# 12  
Old 04-06-2016
Quote:
Originally Posted by venkat918
Hi ,

I have amended in to log file . It is working perfectly. But i observed the files are moving to different path which it seems the script is not working as expected.

Code:
#!/usr/bin/bash
echo "Finding files that are 90+ days old in the server.  Output will be a list of files to be moved:"

if find /var/opt/projects/apps/. -name "*.gz" -mtime +1 -print -exec echo  mv {} /var/opt/projects/apps/temp/ \; >file1.txt
then    echo 'Script completed successfully.'
else    echo 'One or more errors are reported above.'
        exit 2
fi

O/p

Code:
mv /var/opt/projects/apps/./temp/tmp0.39455717678172897.gz /var/opt/projects/apps/temp/
/var/opt/projects/apps/./temp/tmp0.42892912234008185.gz

With the script you have shown us the output should either:
Code:
Script completed successfully.

or:
Code:
One or more errors are reported above.

Not:
Code:
mv /var/opt/projects/apps/./temp/tmp0.39455717678172897.gz /var/opt/projects/apps/temp/
/var/opt/projects/apps/./temp/tmp0.42892912234008185.gz

If the output produced by the script was:
Code:
Script completed successfully.

and the contents of file1.txt was:
Code:
mv /var/opt/projects/apps/./temp/tmp0.39455717678172897.gz /var/opt/projects/apps/temp/
/var/opt/projects/apps/./temp/tmp0.42892912234008185.gz

and you want to actually move /var/opt/projects/apps/./temp/tmp0.39455717678172897.gz to /var/opt/projects/apps/temp/tmp0.39455717678172897.gz, remove the echo from the script.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Move directory recursive and leave symlinks at source

Looking for a script or command to - Move a very large directory with tens of thousands of files and sub-directories recursively (filenames can include spaces) and replace with symlinks pointing to the new location at the same time so there is no downtime Looking for speed + safety :o (5 Replies)
Discussion started by: carnagel
5 Replies

2. UNIX for Beginners Questions & Answers

Move directory with rsync and delete from source

I need a rsync command which will exclude certain files and directories from source and copy the rest. I got this command working, sudo rsync -avzh --exclude 'bin' --exclude 'braintree' --exclude 'colinmollenhour' --exclude 'composer' --exclude 'doctrine' --exclude 'fabpot' --exclude... (2 Replies)
Discussion started by: Siddheshk
2 Replies

3. Shell Programming and Scripting

How Create new directory and move files to that directory.?

Hi All, We have main directory called "head" under this we have several sub directories and under these directories we have sub directories. My requirement is I have to find the SQL files which are having the string "procedure" under "head" directory and sub directories as well. And create... (14 Replies)
Discussion started by: ROCK_PLSQL
14 Replies

4. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

5. UNIX for Dummies Questions & Answers

Zip all files in a directory and move to another directory

Hi, need to zip all files in a directory and move to another directory after the zip.. i am using this one but didnt help me... zip -r my_proj_`date +%Y%m%d%H%MS`.zip /path/my_proj mv in_proj_`date +%Y%m%d%H%M%S`.zip /path/source/ i am trying to zip all the files in my_proj... (0 Replies)
Discussion started by: dssyadav
0 Replies

6. Shell Programming and Scripting

Move all files from source to destination directory based on the filename

Move all files starting with a specific name to different directory. This shell script program should have three parameters File Name Source Directory Destination Directory User should be able to enter ‘AB_CD*' in file name parameter. In this case all the files starting with AB_CD will... (1 Reply)
Discussion started by: chetancrsp18
1 Replies

7. UNIX for Dummies Questions & Answers

move all 2008 year's file to destination directory

I am trying to move file created/modified in 2008 year to <new directory>. But trapped badly in Xargs {}. Looks like mv is not getting destination file properly. It assumes source file s to be destination directory n gives me erroir. "Target must be a directory" Run- #/home/mktrisk: find... (4 Replies)
Discussion started by: kedar.mehta
4 Replies

8. UNIX for Dummies Questions & Answers

Move all files in a directory tree to a signal directory?

Is this possible? Let me know If I need specify further on what I am trying to do- I just want to spare you the boring details of my personal file management. Thanks in advance- Brian- (2 Replies)
Discussion started by: briandanielz
2 Replies

9. UNIX for Advanced & Expert Users

rsync: taking advantage of files in different directory other than destination

Dear Folks, I have to backup pgsql database dump everynight on a routine. The database dump actually contains sql(text) statements. The actual size of the database dump is aroung 800 MB. Between two days backup, only few lines of statements are modified/added/deleted. I dont want to do... (1 Reply)
Discussion started by: rssrik
1 Replies
Login or Register to Ask a Question