LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 04-11-2008, 09:50 AM   #1
Curtix
LQ Newbie
 
Registered: Apr 2008
Posts: 13

Rep: Reputation: 0
Cp with Cron


Where can I get some good Very basic example scripts to do a nightly copy.
I want to
Code:
cp -r /var/whatever to /backup/whatever_currentdate
and run it every night automatically.
Thanks.
 
Old 04-11-2008, 09:58 AM   #2
b0uncer
Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
From (try: 'man -k cron')
Code:
man 5 crontab
Quote:
EXAMPLE CRON FILE
# use /bin/bash to run commands, instead of the default /bin/sh
SHELL=/bin/bash
# mail any output to ‘paul’, no matter whose crontab this is
MAILTO=paul
#
# run five minutes after midnight, every day
5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
# run at 2:15pm on the first of every month -- output mailed to paul
15 14 1 * * $HOME/bin/monthly
# run at 10 pm on weekdays, annoy Joe
0 22 * * 1-5 mail -s "It’s 10pm" joe%Joe,%%Where are your kids?%
23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
5 4 * * sun echo "run at 5 after 4 every sunday"
Oh, and do read the rest of the file for more information. To edit the crontab file,
Quote:
usage: crontab [-u user] file
crontab [-u user] { -e | -l | -r }
(default operation is replace, per 1003.2)
-e (edit user's crontab)
-l (list user's crontab)
-r (delete user's crontab)
And lastly, your command would probably look something like
Code:
10 0 * * * cp -r /var/whatever /backup/`date +%m-%d-%y`
if you wanted to run it 00.10 every night. I haven't tried with that date command, but you should, if you plan to use it.

The time fields are (asterisk means "every time"):

minute hour day_of_month month day_of_week

where the weekday is a number from 0-7 where 0 or 7 means typically Sunday, unless you use names.

Last edited by b0uncer; 04-11-2008 at 10:06 AM.
 
Old 04-11-2008, 10:14 AM   #3
Curtix
LQ Newbie
 
Registered: Apr 2008
Posts: 13

Original Poster
Rep: Reputation: 0
Thanks. I sorta understood cron, just more how to get the date on the end of the copy.
Rock on.
 
  


Reply

Tags
backup, cron, date


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
cron file 000-delay.cron (it is on my FC5) - what is the purpose? jtmoon Linux - Server 1 03-08-2007 11:15 AM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U Suse/Novell 11 01-04-2007 01:57 AM
Can any one plz explain why/what for cron.d, cron.daily, cron.weekly etc are there. mavinashbabu Linux - Newbie 4 09-21-2006 01:50 PM


All times are GMT -5. The time now is 03:27 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration