Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
07-18-2003, 07:36 PM
|
#1
|
LQ Newbie
Registered: Jul 2003
Posts: 3
Rep:
|
Can I make a Cron job to synch/transfer a file from a folder to another FTP?... read
I've got a file hosted in one of the folder of my website account running on Linux. What I'd like to see if its possible to create a Cron Job to synch that specific file to the another folder on another website (via FTP I would guess)
The reason for this is that it's a highly requested file that in turn is consuming a lot of bandwidth and is updated almost daily by another user of my site with FTP privileges. I've setup a redirect to the file on the other site, but I would like for the synching to happen automatically, instead of me by hand. Or is there another way to do this? Cron jobs is the only thing that came to mind but I don't know if it's designed for such use.
|
|
|
07-18-2003, 10:04 PM
|
#2
|
Member
Registered: Jun 2001
Location: Recycle Bin
Distribution: Linux & Everything else on VirtualBox
Posts: 144
Rep:
|
|
|
|
07-18-2003, 10:22 PM
|
#3
|
Member
Registered: Oct 2001
Location: CAMBRIDGE, MA USA
Distribution: RH9 Kernel 2.4.20-18.9
Posts: 69
Rep:
|
I'm not sure that I understand the problem. Do you want to syncronize one file (it changes on two or more machines and the changes need to be propagated to all machines) or is there one file that changes on one machine and you want to push/pull those changes to one or more other machines?
If yours is the latter case and this is a page that is "served" to the public, I would put a cron job on the receiving machinge using wget or GET since this way you do not need to store passwords in files on either machine. Both wget and GET can fetch files that are only newer than a certain date, so you'll have to write a tiny wrapper script for the cron job to get/store the file date of last downloaded file.
Come to think of it, if you have lwp-mirror installed, it will do it all for you w/o a wrapper. And rsync could do it too, but again, there are security issues.
-G
|
|
|
07-18-2003, 11:14 PM
|
#4
|
LQ Newbie
Registered: Jul 2003
Posts: 3
Original Poster
Rep:
|
the changes are on one machine and it needs to be synched to another machine... the problem here is that the machine where I do have access to cron jobs is the one where the file changes, and the machine where I want to transfer the files to I only have FTP access.
sooo, there are 2 solutions as far as I can see. One is to run a program in the background on my PC to periodically synch 2 FTP folder on 2 separate servers (via a utility of some kinds, i'm sure i've seen one or two before)
or the other is to run that command suggested in the first reply to my thread above, but as I understand it, that link above explains how to pull a file. I want to actually upload a file to the other machine. I'm assuming, since Linux has every command imaginable, it probably has an upload command as well.
|
|
|
07-19-2003, 12:26 AM
|
#5
|
Member
Registered: Oct 2001
Location: CAMBRIDGE, MA USA
Distribution: RH9 Kernel 2.4.20-18.9
Posts: 69
Rep:
|
In that case you may want to look at ncftpput (part of the ncftp distro). Assuming that changing_file is the file that you want to upload a script like this should work in cron:
Code:
#!/bin/bash --norc
file=changing_file
if test ! -e $file.upload_time
then
touch $file.upload_time
fi
if test $file -nt $file.upload_time
then
if ncftp -u some_user -p some_password \
some.host.org /home/me/upload_dir $file
then
date >> $file.upload_time
else
echo -n "ERROR: Did not upload file! "
date >> $file.upload_time
fi
fi
WARNING I have not tested this, just whipped this up in the "reply" box. Use at your own risk. But I think it will work
-G
|
|
|
07-19-2003, 04:25 AM
|
#6
|
LQ Newbie
Registered: Jul 2003
Posts: 3
Original Poster
Rep:
|
that package doesn't exist on my host's server. Thank you for taking the time to help me though.
However, I did quite a bit of research after I discovered rsync that is installed on my host's computer.
Does anyone have any experience with rsync? like I said above, I would need to sync a file from a local folder on the Linux server to another server via FTP.
|
|
|
07-19-2003, 11:03 PM
|
#7
|
Member
Registered: Jun 2001
Location: Recycle Bin
Distribution: Linux & Everything else on VirtualBox
Posts: 144
Rep:
|
Well using the link I provided above you could write a script that access the first server ftp and get the file, then quit that server and access ftp the second server and put the file.
IE create a text file named 'ftpscript1.txt' with:
user username password
cd subdirectory
prompt
get file
quit
and run 'ftp -n ftp.server1.com <ftpscript1.txt'
Then create a text file named 'ftpscript2.txt' with:
user username password
cd subdirectory
prompt
put file
quit
and run 'ftp -n ftp.server2.com <ftpscript2.txt'
You may need to put binary in the ftpscriptX.txt file.
NOTE: This is from the link above and I just modified it to your problem, and did not test it.
So you would have a script like this:
#!/bin/bash
ftp -n ftp.server1.com <ftpscript1.txt
ftp -n ftp.server2.com <ftpscript2.txt
Then you run crontab to add the file.
|
|
|
All times are GMT -5. The time now is 04:32 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|