Cron Job to copy a file to another location at a time


I am trying to write a cron job that will basically copy a file from location1/file.txt and copy it to location2/file.txt at a certain time and day of the week e.g. Monday @ 11am - any pointers would be much appreciated.

Well, let’s walk through this.

First: What’s the command to do this?

“cp” is the command to copy a file, and it takes the source and destination paths as the next two arguments. You’ll need to format the two file paths as absolute paths (i.e, “/home/username/path/to/file.txt”); once you’ve got the paths in that format, the command will look something like:

If you have your DreamHost user set up to allow shell logins, you can connect using an SSH client and try running this from the command line to make sure it works.

To create a cron job, head to the “Goodies: Cron Jobs” section of the DreamHost Panel and create a new cron job. To make it run at a specific time and date, switch “when to run” to “custom”. This will make a bunch of options show up to choose a specific time, you’ll want:

Minutes: Selected minutes (pick 00)
Hours: Selected hours (pick 11)
Day of Month: every day (we’ll get the “Monday” bit in later)
Month: every month
Day of Week: Selected Days of Week (pick Monday)

For what it’s worth, this is equivalent to a cron job specification of:

except more readable. :slight_smile: