simple cron question

msgx10mx

New Member
Messages
9
Reaction score
0
Points
0
I want to set up a cron job to copy a file from one directory to another directory (which is a subdirectory)

Can I do this directly from the cron setup or do I need to write a shell script to handle? Also, do I need to include the full path to the files?

If I was in the directory where the file was located, I would normally just type

cp file1.txt /targetdirectory

But I don't think that is working with the cron job...

---------- Post added 06-01-2012 at 02:46 AM ---------- Previous post was 05-31-2012 at 07:24 PM ----------

Ok, I was able to do what I wanted by creating a simple shell script... in the cron job I used

/usr/bin/sh [full path to script] >> [full path to error log]

in the script I had

#!/bin/bash

cp [full path to file] [full path to desired location]
 

abxx10mx

New Member
Messages
3
Reaction score
0
Points
0
The simplest approach would be to stuff all your code into a php file and then simply have cron execute the script every now and then. You want to make sure your script is actually working of course. Just enter the URL and try it. If it works in the Browser it'ss work via cron.
 

buck15

New Member
Messages
3
Reaction score
0
Points
0
You might want to use the -p option of the cp command to preserve owner, group, permissions etc. on the copied file.

Regards,
Buck.

I want to set up a cron job to copy a file from one directory to another directory (which is a subdirectory)

Can I do this directly from the cron setup or do I need to write a shell script to handle? Also, do I need to include the full path to the files?

If I was in the directory where the file was located, I would normally just type

cp file1.txt /targetdirectory

But I don't think that is working with the cron job...

---------- Post added 06-01-2012 at 02:46 AM ---------- Previous post was 05-31-2012 at 07:24 PM ----------

Ok, I was able to do what I wanted by creating a simple shell script... in the cron job I used

/usr/bin/sh [full path to script] >> [full path to error log]

in the script I had

#!/bin/bash

cp [full path to file] [full path to desired location]
 
Top