Cron job setup - copy file


#1

I need a cron job to copy 1 file from 1 folder/domain to another.

They are on different accounts.
I have it working between domains on the same DreamHost account with this:

cp -f /home/user/domain.com/folder/file.jpg /home/user/domain.com/folder

I understand that I get the error “folder does not exist” when the domain is on a different DreamHost account, since it probably wants a ftp user/pwd

How do I set the ftp user/pwd in a cron job?

Or should I use a script or php and run it? If so how?
I found a sh script and tried to run it, but no luck.

[code]#!/bin/sh

Put FTP server details here

SERVER="domain.com"
USERNAME="FTP user"
PASSWORD=“FTP password”

local directory containing source backup file

SOURCEFILES="/home/user/domain.com/folder"

remote server directory path in which backup needs to be put in

BACKUPDIRCTORY="/home/user/domain.com/folder/"

login to remote server

ftp -n -i $SERVER <<EOF
user $USERNAME $PASSWORD
cd $ BACKUPDIRCTORY

mput $ SOURCEFILES/file.jpg
quit
EOF[/code]
and then I used:
curl http://domain.com/copy.sh
but that did not work also.

Please help and give me a ready solution, I have been searching and trying for hours now and am stuck.


#2

As far as a ready solution, I’d have to sit down and work it out, but I’d look for something using rsynch. Once I had it working from the command prompt then I’d turn it into the cron job


#3

I don’t know anything about rsync, but seem an option as what I see in the wiki.
As long as it does the job to copy the file and overwrite the existing one at the set interval, I will be very happy


#4

Anybody has a solution, or should I just forget it.
I spent about 5 hours more on Google and trying, after the last message, but no success.

If DH support has a solution ( have NOT yet ask for official support/help ), it would be very welcome


#5

My choice would be rsync as well but you’d want/need to set up passwordless SSH to make that ultimate: http://halfelf.org/2012/passwordless-ssh/

And then the rsync is normal: http://www.cyberciti.biz/tips/linux-use-rsync-transfer-mirror-files-directories.html


#6

Sorry, guys, you are talking to a NOOB here who did his best at solving it himself.
I could not, so I ask for help, which means a ready to use solution.

If that is not available, I will just ask DH to transfer the domain to the same account and problem solved.
Yes, I can backup my files and database and have it all work again on a new/other server. Won’t be the first time.

So please no techno babble, just a ready to the point solution.

Thank you

PS …

As a DH working/service/support … Ipstenu-DH
Shouldn’t DH have somewhere ready to use, easy to apply, stuff like this.
Or am I the first one ever to ask this question?

DH should have a KNOW-HOW (always up to date) for any questions/ready made/… well what ever

Yes, I could not solve this, but the many years with DH and the forum …
How many times are the same questions asked ???
Believe me I search the forum, but the search here really S…S, since it only looks for words, not combinations as words


#7

I think you were almost there when you tried ‘curl’, except you forgot to use the ‘-o’ option to make it write an output file. Without that, the output goes to stdout, which in the case of a cron job just gets lost. Where you had

just change it to

and it should work. P.S. since you ask for a ready to use solution I have actually tested this with a cron job that runs every minute and does

and it works correctly. Now browsing to ‘now.html’ in my domain gives the up-to-the-minute time in Barbados.


#8

Asking for help in a forum is asking for pointers on which direction to take, or to see if there is something that your missing, or perhaps get pointed to a link that has a ready made solution already created. It’s not asking for someone to donate programming time.

The “ready made solution” is what you ask a paid designer/admin to do for you.

One thing that makes a ready made solution hard in this case is you have at least 3 things to get working… first, passwordless login, then the script itself, then the automation with cron. Sure someone could do one of those for you (the script itself), but does that really get you closer to it working on your domains?

FWIW what you are trying to do is a “backup”. Granted it’s one file that you are “backing up”, but none the less that is effectively what you are wanting to do. I haven’t looked to see if there is a backup script for dreamhost webserver to dreamhost 50g private backup space that can be tuned to back up just a single file. If THAT exists it’s trival to change the server from hanjin to something else (i.e. the other webserver)

Whether dreamhost should make this type of script readily available in some sort of library is debatable. In reality there is a much larger library called google. Another consideration is why would two “accounts” be sharing a single file? If the sites are so related to each other then why are they on completely different accounts?

Try this for examples


#9

When I first switched to DH, all this was slightly confusing to me. However, I took the time to learn how to use some of the tools that are nicely available in DH:

SSH
rsync
SFTP
cron

I am far from a pro, but once I got the hang of it, I do not think I would want to use any ready-made solutions.
The reason is that using SSH, SFTP and rsync…coupled with cron…is so flexible that I can write the exact scripts I need for each website I manage.

What I am getting at is: DH already provides these tools…they are built in and work nicely. It just takes a little digging and learning to use them…but once you do your time will pay off because you now have skills that you can use on any Linux webserver, as well as all of your DH hosted sites.


#10

It is only a between 20 and at the most 60 kb file.
No large backup and stuff like that.

But thank you, I will try @tomtavoy’s solution/post and if that does not work, I will just transfer the whole domain to the other server, so they are both on the same server/account.
No problem, just tried to avoid that

@Lakerat
I know you are always ready to help here and anyone, but understand, not everybody has the technical skills you and other regular posters have and for NOOBS like me and about 90%+++ of the same people on this or any technical forum, most of you talk way to technical to even understand what you write.

Well at least I tried, did not work, so now I have to put support to work and transfer the domain.

God bless you all and Merry X-mas, Happy New Year
[hr]

you posted, before mine was ready.
I have been with the GREAT DH over 7 years, after 4-5 many different hosting companies. For me DH is the best.
I have learned a lot and solved about 95% of my own problems over the years and also when ever possible helped others whom where even more NOOBS then me.

Please, don’t make this thread in to a … well we all understand.
If it yurns out to become one of those threads, lets have at least DH-moderator move it to the appropiate forum, since my problem will not get solved the easy way.
[hr]
and one more thing,
Why did I wasted so many hours?
Mostly waiting and waiting. Found new possible solutions by Google search and tried them all.

Problem is … had to wait, always minimum of 10 minutes before I would know if it worked, since that that is the minimum time DH allows to set a cron job.

A simple TEST Button would be nice … TEST Cron Job Now … DON’T wait 10 minutes


#11

“had to wait, always minimum of 10 minutes before I would know if it worked, since that that is the minimum time DH allows to set a cron job”

You can get that down to 1 minute as follows:

(or change ‘vi’ to the name of your preferred editor, or omit to get Dreamhost’s choice of default editor) which will bring up the cron table in an editor. Locate the line for the cron job which you want to run every minute. At the beginning of that line, change ‘/10’ (meaning every 10 minutes) to '/1’ (meaning every minute). Save and exit. Done.

(There will probably be some verbiage about “###— Changes made to this part of the file WILL be destroyed!” but do not worry about that. Changes which you make here will be reverted next time you make a change to the cron table from the Dreamhost panel.)