Click to See Complete Forum and Search --> : cron question


mytigor
03-01-2004, 04:33 PM
I have to automate several tasks written in one script for a school project. The last problem is: Perform a daily backup of a directory of user A to a directory of user B. This will work from my script and from a command line:

cd /home/user B/directory user B
rm -rf directory user B
cp -a /home/user A/directory user A /home/user B/directory user B

When I try to use the above commands in a cron job the directory never gets copied, and I don't get any error messages.
I have read that I can write a second script to perform the backup, and have a cron job point to the second script from the first script. Is this do-able? If so, how.
I have read the man page and help files and can't figure out how to make this work. I will be running the script as su. Thanks, Igor.

ph34r
03-01-2004, 04:46 PM
Do you actually have spaces in the file/directory names? Wrap them in quotes if you do. Also, I'd just make a script to do the backup, then call that script from cron.

knute
03-01-2004, 04:50 PM
Either that or escape the spaces with the backslash (\) as in "User\ B"

HTH

mytigor
03-01-2004, 06:14 PM
Wow, thanks for the fast response,

I don't have any spaces in the filenames.

I have a script to do the backup,

I don't know how to call the script from cron though.

Could you instruct. Thanks, Igor.

Hayl
03-01-2004, 06:29 PM
it explains how to do that in the man page for cron.

man cron.

but for the lazy add the following to your /etc/crontab to have it run at 3am on the 6th day of the week:

0 3 * * 6 root /path/to/your/script

the sequence of numbers, username, and command of each cron line is:

min hour dom mon dow user command

bwkaz
03-01-2004, 08:47 PM
Or throw it into /etc/cron.daily to run once a day, /etc/cron.hourly to run once an hour, /etc/cron.weekly to run once a week, etc. The only thing is, I don't think you have control over when in the hour, day, or week that it runs.

mytigor
03-01-2004, 09:31 PM
Do I put the backup.sh script I wrote or the
0 3 * * * cp -a /home/userA/directoryA /home/userB/directoryB in the /etc/cron.daily file. And once I have something in there, how do I call on it from my original script.

It's not that I actually need to schedule this cron job, as much as I have to show the automated daily backup in the script for my class project. If anyone knows any other method besides using cron, that would be ok. I just have to show the backup in the script. Many thanks, Igor.

bwkaz
03-01-2004, 11:08 PM
You can just put the backup script in there (or make a symlink that points at the real location of the backup script). Default distro installations of cron already have jobs set up to run hourly, daily, and weekly that collect all executables in the cron.hourly, cron.daily, and cron.weekly directories (they're not files) and then execute them.

And once I have something in there, how do I call on it from my original script. I don't think I understand this question? You don't have to call it from anywhere on your own -- if the script is put into one of those directories, it should run hourly, daily, or weekly. Your crond process takes care of scheduling it, assuming your computer is running when the job is scheduled.