Need help writing a script for a Cron Job to copy files.

I need someone to write me a short cron job script to copy files from an NFS mount to an external hard drive on a daily basis.

The best situtation would be to only copy files that have changed, but it could also just delete everything on the external drive and recopy it.

I'm a total noob with respect to this, so I need to be walked through it.

This is worth 500 Points.
Who is Participating?
grbladesConnect With a Mentor Commented:
You could use rsync as it will automatically copy only the files which have changed :-

rsync /path/to/source/files /destination/path
You will probably also want to use the '-a' option so that all subdirectories are copied aswell.
The '--delete' option will delete files in the destination path which are no longer in the source path.
The '-n' option will perform a dry run showing which files would have been copied.
Kent OlsenConnect With a Mentor Data Warehouse Architect / DBACommented:
Hi gerhardub,

As far as the script goes, it won't care about the device where the files currently reside, nor will it care about the destination device.  All the script will do is copy files.

The script can be as short as a single line.  Note that you'll have to use the corrent path/filenames.

#  Copy all of the messages files to /tmp
   cp  /var/log/messages* /tmp  

So the trickiest part is figuring out exactly when you want the copy to execute.

Then set up the crontab to run at the desired time.  Start by running crontab

   crontab -e                  # this displays the cron jobs in your default editor

Edit the file and add a line like this:

  * 1 * * * /home/me/scripts/

Then exit the editor (with save)

The job will run every morning at 1AM.

Good Luck,
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.