LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-26-2001, 09:35 PM   #1
jonfa
Member
 
Registered: Mar 2001
Location: FL
Posts: 257

Rep: Reputation: 30
creating cron jobs


How does one go about creating cron jobs? For example, How can I empty the contents of a directory to a floppy, cd, or zipdrive every week? Are there any how-to's, websites, or better yet, any scripts people have already written?

Thanks,

Jon
 
Old 06-27-2001, 03:34 AM   #2
jharris
Senior Member
 
Registered: May 2001
Location: Bristol, UK
Distribution: Slackware, Fedora, RHES
Posts: 2,243

Rep: Reputation: 47
You control your cron job by using the crontab command or by editing /var/spool/cron/crontabs/<username>. If you wanted to schedule a job as root you would run
Code:
crontab -e
This will start whats appears to be vi (this will scare you if you haven't used it before) to let you edit the file. When you leave the file it notifies cron about the change so the updates take place.

If you wanted to remove all files in a directory called /myDir once a week, say at 09:00 on a Monday then you would have something like this in your crontab
Code:
0 9 * * 1 /bin/rm -rf /myDir/*
The format of the crontab is mins hrs day-of-month month weekday cmd and the range of these values are
Code:
mins :: The minutes after the hour. :: 0-59
hrs :: The hours of the day. :: 0-23  (0 = midnight)
day-of-month :: The day within a month. :: 1-31
month :: The month of the year. :: 1-12
weekday :: The day of the week. :: 0-6  (0=Sunday)
If the command produces any output then it will be emailed to the user. To avoid this you either need to ensure that your command doesn't produce anything or redirect any possible output using something like
Code:
myCommand > /dev/null 2>&1
Does that make sense?

HTH

Jamie...
 
Old 06-27-2001, 11:31 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
if your under redhat 6.2+ it's a damn sight easier to just add an entry to the /etc/crontab file. Maybe create a new directory in line with the file, and just put a script file in that directory maybe... MUCH easier than actually understanding cron!

Chris
xxxx
 
Old 06-27-2001, 11:10 PM   #4
hazza96
Member
 
Registered: Apr 2001
Location: Brisbane, Australia
Distribution: Ubuntu
Posts: 146

Rep: Reputation: 15
Put the executable in the /etc/cron.weekly directory.

I run Mandrake 7.2 and it has several directory's under the /etc directory. cron.hourly, cron.daily, cron.weekly, cron.monthly.

Any executable in those directorys get executed at the appropriate interval.
 
Old 05-26-2002, 12:06 PM   #5
medamnit
LQ Newbie
 
Registered: Apr 2002
Location: Australia
Distribution: RedHat
Posts: 16

Rep: Reputation: 0
i've popped a file in the cron.daily and wondering how to make it run. the file simply clears out all "*.CKP" files on the system but it doesn't seem to be running. any special way to enable it or they should just run when in the cron.daily directory?

thanks
medamnit
 
Old 05-26-2002, 05:05 PM   #6
hazza96
Member
 
Registered: Apr 2001
Location: Brisbane, Australia
Distribution: Ubuntu
Posts: 146

Rep: Reputation: 15
Is it executable? Have you checked the permissions? What are they?

Have you tested the script manually? Did it work?

What are .ckp files? and why do you need to clear them daily?
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron Jobs XaViaR Linux - General 1 06-23-2005 06:57 PM
cron jobs working2hard Linux - Software 0 07-28-2004 05:31 PM
CRON Jobs scottpioso Linux - Software 63 11-28-2003 06:45 PM
Linux Cron Jobs dibyendra Programming 0 08-19-2003 09:20 PM
cron jobs Zyanid Linux - Software 0 08-27-2002 05:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:43 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
Open Source Consulting | Domain Registration