LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 08-04-2004, 02:41 PM   #1
sdebiasio
LQ Newbie
 
Registered: Jul 2004
Posts: 22

Rep: Reputation: 15
Alrighty, I'm back. Again. Cron Job ...


I am trying to schedule this backup job using CRON. The test I tried before in which I just scheduled an email to be sent worked fine. But no such luck here.

Here is what I did:



1) I created a file called backup.sh in the /etc/cron.daily folder, which had this as its contents:

#!/bin/bash
tar -czvf /backupdirectory/backup.tgz /directorytobackup


2) I installed this cron job in crontab:

12,32 * * * * /etc/cron.daily/backup.sh



Am I placing the backup.sh file in the wrong directory? Also, do I need to create an .sh file at all? Can't I just put the backup command right in the cron job instead of calling to the backup.sh file?

I'm so confused, I've been at this all afternoon.

Thanks in advance ....
 
Old 08-04-2004, 02:47 PM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,165

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Scripts in the /etc/cron.daily folder are run by cron automatically once a day (usually at 4 AM). You're right, you can just have a crontab entry that looks like:

12,32 * * * * tar -czvf <whatever> <whatever>

in your crontab. If you want a backup, I suggest adding the -p flag to tar to tell it to preserve permissions (you'll need to be root for this to work if there are files not owned by you).
 
Old 08-04-2004, 02:56 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 12,175

Rep: Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784
Don't if what you posted was a typo but 12 32 * * * is invalid.

FIELD VALUE
------------------
minute 00 to 59
hour 00 to 23 (military time)
day 1 to 31
month 1 to 12
weekday 0 to 6 (0=Sunday) Note: Linux uses sun, mon...

Last edited by michaelk; 08-04-2004 at 03:00 PM.
 
Old 08-04-2004, 03:00 PM   #4
osvaldomarques
Member
 
Registered: Jul 2004
Location: Rio de Janeiro - Brazil
Distribution: Conectiva 10 - Conectiva 8 - Slackware 9 - starting with LFS
Posts: 519

Rep: Reputation: 34
Hi sdebiasio,
You are trying to run your job at 32:12H of each day. I guess you want at 12:32H. The first field is the minute, the hour is the second.
 
Old 08-04-2004, 03:02 PM   #5
sdebiasio
LQ Newbie
 
Registered: Jul 2004
Posts: 22

Original Poster
Rep: Reputation: 15
Hmm I think I need another coffee! No it wasn't a typo, that's what I used.

Let me try this again. You guys are great.
 
Old 08-04-2004, 03:30 PM   #6
sdebiasio
LQ Newbie
 
Registered: Jul 2004
Posts: 22

Original Poster
Rep: Reputation: 15
Ok - I scheduled this cron job in crontab:

25 15 * * * tar -czvf /backup directory/backup.tgz /directory to backup

and then installed it by typing "crontab crontab" at the command line.

It didn't work.

Isn't the syntax directing it to execute at 3:25pm on Wednesday? I am wondering why this didn't execute.
 
Old 08-04-2004, 03:58 PM   #7
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,165

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
The syntax you gave tells it to execute at 3:25 PM every day. So it should've executed today. For sanity's sake make sure crond is running and chack your cron log in case there were errors (it should be in /var/log/cron). Also, you might want to provide the full path to tar just to be safe.
 
Old 08-04-2004, 04:27 PM   #8
sdebiasio
LQ Newbie
 
Registered: Jul 2004
Posts: 22

Original Poster
Rep: Reputation: 15
How do I make sure crond is running?

I checked the log file and I don't see any errors.

Thanks ...
 
Old 08-04-2004, 04:48 PM   #9
osvaldomarques
Member
 
Registered: Jul 2004
Location: Rio de Janeiro - Brazil
Distribution: Conectiva 10 - Conectiva 8 - Slackware 9 - starting with LFS
Posts: 519

Rep: Reputation: 34
Hi
You just enter
Code:
HHH:~# ps ax|grep cron|grep -v grep
  795 ?        S      0:00 crond
If it is running you will see it.
By the way I would put it into a sub-shell, redirecting the output to null
Code:
25 15 * * * (tar -czvf /backup_directory/backup.tgz /directory_to_backup) >/dev/null 2>&1
I didn't understand what you meaned by "I scheduled and installed". By the manual, all you have to do is enter "crontab -e" as the user owner of that queue. crontab will open your preferred editor for you to edit the job. When you save the edit and close the editor, it does a consistency test of the jobs and submit to the cron queue. You can see the scheduled jobs with "crontab -l".
 
Old 08-05-2004, 09:02 AM   #10
sdebiasio
LQ Newbie
 
Registered: Jul 2004
Posts: 22

Original Poster
Rep: Reputation: 15
Thanks for your help.

Oddly, the backup actually ran - precisely an hour after I scheduled it. It was scheduled for 4:35 in the Cron Job and ran at 5:35 instead. To test this, I just scheduled a job for 7:30 in crontab and it ran at 8:30.

Strange ...
 
  


Reply


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
Cron Job petenyce Linux - Newbie 5 10-11-2005 05:03 PM
need help with cron job parthcorp1 Linux - General 2 02-01-2005 12:37 PM
CRON Job tommytomato Fedora 12 09-13-2004 01:38 AM
cron job ? johnyy Linux - Software 3 12-10-2003 07:00 PM
Cron Job imanahmadi Linux - Newbie 1 07-04-2003 12:39 AM


All times are GMT -5. The time now is 09:35 PM.

Main Menu
Advertisement
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