LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   creating cron jobs (https://www.linuxquestions.org/questions/linux-general-1/creating-cron-jobs-3732/)

jonfa 06-26-2001 09:35 PM

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

jharris 06-27-2001 03:34 AM

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...

acid_kewpie 06-27-2001 11:31 AM

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

hazza96 06-27-2001 11:10 PM

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.

medamnit 05-26-2002 12:06 PM

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

hazza96 05-26-2002 05:05 PM

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?


All times are GMT -5. The time now is 10:23 PM.