Cron jobs

Thread Tools Search this Thread
Operating Systems Linux Cron jobs
# 1  
Old 10-27-2009
Cron jobs


I am a Linux administrator (newbie) in my company. The distro being used in the servers here is Centos 5.3

Just need to know, as a Linux administrator is it better for me to use /etc/crontab to set my cron jobs. I do not want to use the crontab -e to schedule my cron jobs.

That means can I edit the default settings (to different time settings) in etc/crontab in order to get my database to backed up?

And another question is, how do I set the cron job to only show the current week's backup (in the database backup directory) and remove the previous week's backups.

One week would mean Monday to Saturday.

Pls help.


Last edited by pludi; 10-27-2009 at 05:16 AM..
# 2  
Old 12-28-2009
Unless there's real urgent need to change it, you should leave /etc/crontab as is. The primary use of /etc/crontab is to allow the system to manage its own log files and environments. If there are tasks that you would like to include in the system housekeeping to be maintained at the times listed within /etc/crontab, they can be included in the appropriate /etc/cron.<time> file.

For purposes of a database backup, 'crontab -e' is the best option. Create your crontab entry and reference a script. This way you will not need to modify your crontab entry unless you need to change the time of your backup. All other aspects of the backup will be controlled from the script.

Deleting the old backup files will depend on how you perform your backups. If you perform a full database backup every night, then you can use something along the lines of this at the top of your script to remove the oldest file prior to performing the nightly backup:

find /backup-dir -atime +7 -exec rm ()\;

This will remove any files older than 7 days from the directory. Since this executes every night, there will only ever be one file deleted per night.

If you're performing a full backup the first night, and incrementals on subsequent nights, then you'd want to only perform the removal operation prior to your full backup with something similar to the following prior to performing the backup (assuming you perform your full backup on Monday):

if [ "`date +%a`" == "Mon" ]
    cd /backup-dir
    /bin/rm backup-files

That will preserve your incremental backups until the night of your next full backup.

Hope this helps.

Last edited by Scott; 12-28-2009 at 11:06 PM.. Reason: Added code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cron Jobs

How to see which cron jobs are not running? (2 Replies)
Discussion started by: rahul.raj1989
2 Replies

2. Red Hat

Cron jobs

I'm running cronjobs on a redhat 5.X. Cronjobs are getting failed frequently so how to find the root cause (2 Replies)
Discussion started by: karthik9358
2 Replies

3. Solaris

Cron jobs and at jobs

There are two jobs in Solaris , Cron and at jobs.. I know how to disable or enable cron jobs. How can I enable at jobs and disable it. Kindly help. Rj (2 Replies)
Discussion started by: jegaraman
2 Replies

4. Shell Programming and Scripting

cron jobs

Hi, please help on this am trying to exec the below mentioned cron jobs but its getting failed fro the past two days ###but when am trying to execte the cron by the times 23,29 18 * * * /export/home/inrvgo/thelak/ its getting exec properly please help on this #... (8 Replies)
Discussion started by: thelakbe
8 Replies

5. Shell Programming and Scripting

Help with cron jobs

Hi Frenz, How do we get a cron job running in background to foreground ? (3 Replies)
Discussion started by: mkalase
3 Replies

6. UNIX for Dummies Questions & Answers

cron jobs

Hi, We have a group of hosts using which the cron jobs are submitted... Few days ago i had submitted a cron job in of these hosts, but unfortunately forgot the host name :( Can anyone please help me out in finding this host name from which the cron s submitting the job, i dont want the... (2 Replies)
Discussion started by: bhavanisree
2 Replies

7. Solaris

cron jobs

how to Put a cron entry which should be same script triggered on every Saturday and 1st of every month at 01.00 GMT. 0 2 1 * 6 --( At 2.00 GMT every sat & on 1st of every month) the above syntax is correct? Thanks (1 Reply)
Discussion started by: kurva
1 Replies

8. Solaris

Cron Jobs

I'm trying to run cron jobs to start any inhibited processes after a system reboot. I can schedule th cron, but i'm confused as to how to incorporated the reboot, since reboot is scheduled at different times, once every month. How can I write this to start every 15 min after after a reboot ... (2 Replies)
Discussion started by: Remi
2 Replies

9. UNIX for Advanced & Expert Users

cron jobs

I need to monitor my cron jobs with another unix machine since occasionally the cron will go down on the main server but there are no errors. Can anyone help with a script to write to use the cron on the back up machine to monitor the main server? I am using SCO and the cron jobs have been... (3 Replies)
Discussion started by: rmarral
3 Replies

10. UNIX for Dummies Questions & Answers


Hi, I am a total newbie to all things Unix. I've worked out I need to set up something that will allow me to automatically backup a DB for me, the DB is for a foum system I run. Now, I've only found out I need to use telnet for this, and worked out hwo to log into telnet today. From here... (4 Replies)
Discussion started by: eludlow
4 Replies
Login or Register to Ask a Question