1837097 Members
2210 Online
110112 Solutions
New Discussion

Scripting Help

 
SOLVED
Go to solution
Amiel Tutolo
Frequent Advisor

Scripting Help

I am trying to copy files from one server to another. My problem is that a) My scripting skills leave a lot to be desired. b) I only want to copy files created since yesterday. I would run the script just after midnight and only pull yesterday's files. I am having problems pulling out the date info. Has anyone ever done anything like this? I know also there used to be a thread of helpful admin tools out there as well and I can't find it either.
Live, love and laugh
7 REPLIES 7
Pete Randall
Outstanding Contributor

Re: Scripting Help

Use find:

find /directory_name -type f -mtime +1 -exec your_copy_command {} \;


Pete

Pete
Sean OB_1
Honored Contributor

Re: Scripting Help

Use find to locate all the files that have changed:

find /directory_name -type f -mtime +1

I would save them to a file and then use that file in your copy script:

find /directory_name -type f -mtime +1 > /tmp/changed_files

then reference /tmp/changed_files in your copy script to rcp or ftp them to a new server.

If you had space you could even tar them into a tarball and then just ftp the tarball to the other server.
Amiel Tutolo
Frequent Advisor

Re: Scripting Help

I left one thing out. There will be files in the from directory that go back more than yesterday. My plan was to do a backup and restore of all files and then starting with files say, created on January 14, I would run the script after midnight and only pull files with the January 14th date. I hope this clarifies my question. Thanks
Live, love and laugh
Chris Vail
Honored Contributor
Solution

Re: Scripting Help

Use find to locate your files (with the -mtime argument). Write them into a temporary file:
find DIR -mtime DATE -type f>>/tmp/filenames

Then use tar to copy them into a tarball:
tar cvf /tmp/tarball 'cat /tmp/filenames'

This tarball can be copied off to tape directly; transferred to another machine with ftp, rcp, or scp; or compressed with gzip and left there as an archive.


Good luck
Chris
Amiel Tutolo
Frequent Advisor

Re: Scripting Help

I am trying to use the tar that Chris shows but I get an error stating -

# tar -cvf utldir.tar 'cat /tmp/utldir.log'
tar: cannot open cat /tmp/utldir.log

The file /tmp/utldir.log does exsist. I can do a more on it.

Any suggestions. I have never used tar with a file before.
Live, love and laugh
Amiel Tutolo
Frequent Advisor

Re: Scripting Help

I got it. Thanks everyone. It is all in which `tick' you use. Points have been assigned.
Live, love and laugh