Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-28-2007, 12:23 PM   #1
LQ Newbie
Registered: Nov 2006
Posts: 12

Rep: Reputation: 0
Find & Transfer to FTP Script

I have a program that creates backups of certain files everything into a directory everyday.

My problem is that I would like to make a script to find out the most recent directory created on that same day as the computer as (labelled as year_month_date, ie: 2007_02_28) and then copy that entire directory and its contains and label that as something and transfer to a local ftp server as a secondary backup. This script will be executed every 10am via crontab.

Hopefully this is a newbie questions
Thx for reading my thread


Last edited by DjRakso; 02-28-2007 at 12:24 PM.
Old 02-28-2007, 01:27 PM   #2
Registered: Feb 2007
Location: London
Distribution: debian
Posts: 108

Rep: Reputation: 15
sounds like a job for "find" with the "exec" option.

in case that is not familiar to you, here is an example i found online

    find . -name "rc.conf" -exec chmod o+r '{}' \;
"This command will search in the current directory and all sub directories. All files named rc.conf will be processed by the chmod -o+r command. The argument '{}' inserts each found file into the chmod command line. The \; argument indicates the exec command line has ended. "

using find you can easily find directories created on a certain date and then you just run "cp -a" using the above option.

Old 02-28-2007, 03:01 PM   #3
LQ Newbie
Registered: Nov 2006
Posts: 12

Original Poster
Rep: Reputation: 0
Yup, I got the ftp mostly working....
Just is there a way to like pipe the output of the finds and then get the ftp prompt to copy those files onto the remote server?

find . -name "" -exec chmod o+r '{}' \;
cp -a
ftp -v -n << EOF
user tester tester
cd /backup/
mdel *.*
mput *.*

See at the find line, I want to find the newest directory located in "backup" save that name of that folder (ex: 2007_02_20). The find will cehck to see if the folder as been within 7 days modified. When connected to the remote FTP, goes to the "backup" directory. Makes a directory named like "2007_02_20" and dumps anything from the local comptuer to the remote computer.

Last edited by DjRakso; 02-28-2007 at 03:03 PM.
Old 03-01-2007, 04:44 AM   #4
Registered: Feb 2007
Location: London
Distribution: debian
Posts: 108

Rep: Reputation: 15
Hi, Maybe I am misunderstanding you a bit (I am not quite sure what you are doing with the chmod in the find command). If ftping the files is the cause of your hassle, maybe if you have the option, try using scp. You can use keys and have this work passwordless. In that case, it would almost identical in syntax to using cp and could be pretty simple.

If you have to use ftp, however, I think everything still should be possible using the find exec combination.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
FTP transfer freezes TheRudy Debian 3 01-15-2007 03:16 PM
shell script to transfer file from ftp bbgtilak Linux - General 1 12-27-2006 08:35 AM
Ftp freezes up during transfer GeneralChaos Slackware 2 10-04-2005 09:52 PM
Using BASH script to transfer a file via (s)ftp senther Linux - Newbie 2 07-19-2005 05:47 PM
Is there a script to auto find installed distros & edit Grub clintbrot Linux - Software 3 06-16-2005 11:15 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:18 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration