LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-23-2003, 02:35 PM   #1
titanium_geek
Senior Member
 
Registered: May 2002
Location: Melbourne Australia
Distribution: it died/ macosx
Posts: 2,478

Rep: Reputation: 50
all right, I'm an idiot. cron problems


heheh. I started a cron thread ages ago, but gave up in frustration before I could fix it.

So any way, I would like to ask someone to guide me through this step by step.

**********Here's what I know:********************
1)the format of dates..
2)I have a cron.allow and cron.deny file.

**********Here's what I don't know:**************
3)what to name the file (what extension)
4)where to put it
5)do I need to edit crontab?

anything not here I don't know, so tell me.

titanium_geek
 
Old 07-23-2003, 02:43 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
The nake of the file doesn't matter nor does the location.

I would create a directory called "cron" in the home dir of the user it will be run as:
/root/cron

In that put:
/root/cron/jobs
/root/cron/logs

I put all my scripts in the jobs directory and output the logs to the logs directory (same name as the job with a .log extension)

In the /root/cron dir I create my cron files. If there is only one server it is usually "cron.standard" if it is a 2 system failover "cron.master" and "cron.slave". To load a crontab file (eg cron.standard) run:
crontab /root/cron/cron.standard

You cna check that it has loaded using:
crontab -l
 
Old 07-23-2003, 04:28 PM   #3
CodeWarrior
Member
 
Registered: Mar 2003
Location: US
Distribution: Kubuntu 6.06
Posts: 173

Rep: Reputation: 30
I have only dealt with CRON on Solaris, but I ran into lots of problems with extra spaces and newlines in my cronfile. Be careful about them, seems that cron is sensitive to them. Especially newlines after your line

* 1 * 12 *
 
Old 07-25-2003, 05:55 AM   #4
titanium_geek
Senior Member
 
Registered: May 2002
Location: Melbourne Australia
Distribution: it died/ macosx
Posts: 2,478

Original Poster
Rep: Reputation: 50
*david_ross* thanks. will try it out.
Oh, and how do you make sure that jobs go to "jobs" and logs go to "logs"?

*CodeWarrior* no, I don't think this is the problem... thanks though.

titanium_geek



Last edited by titanium_geek; 07-25-2003 at 05:57 AM.
 
Old 07-25-2003, 06:00 AM   #5
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
That is just where you put the files. So a cron file say "cron.standard" could be:
0 * * * * /root/cron/jobs/backup.pl 2>&1 > /root/cron/logs/backup.log
 
Old 07-26-2003, 09:11 AM   #6
titanium_geek
Senior Member
 
Registered: May 2002
Location: Melbourne Australia
Distribution: it died/ macosx
Posts: 2,478

Original Poster
Rep: Reputation: 50
Ok, so, I have this cron file. I call it cron.mine (?) and put it in cron/jobs. It says:
0 10 * * /root/cron/jobs mail -s pengun "It's 10 o'clock" root
to let it email me whenever it's 10 o'clock. (tell me if i'm right.)
oh, and would it email to user penguin or user root?

titanium_geek
 
Old 07-26-2003, 11:02 AM   #7
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
If you are setting it up the way I suggested it would be the file:
/root/cron/cron.mine
Code:
# This is my cron file (cron.mine)

# Job 1, e-mail penguin when it is 10 o'clock
0 10 * * * mail -s "It's 10 o'clock" -u penguin  2>&1 > /root/cron/logs/mail-at-10.log

# Job 2, set the time every hour
0 * * * * rdate -s ntp.demon.co.uk 2>&1 > /root/cron/logs/rdate.log

# Job 3, backup using my backup script
30 2 * * * /root/cron/jobs/backup 2>&1 > /root/cron/logs/backup.log
I only use the jobs directory for puting the actual scripts in. If is is only a one liner then I wouldn't bother with a script.

This is only the way I do it because I find it easy to use regardless of the user.
 
Old 07-27-2003, 04:42 PM   #8
titanium_geek
Senior Member
 
Registered: May 2002
Location: Melbourne Australia
Distribution: it died/ macosx
Posts: 2,478

Original Poster
Rep: Reputation: 50
thanks. makes more sense than any book or howto. so, how do I get it to recognise it's a cron comand thingy? if I just put it there will it work?

titanium_geek
 
Old 07-28-2003, 03:32 AM   #9
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
No you will need to load the crontab file:
crontab /root/cron/cron.mine

You can check it has loaded using a listing:
crontab -l
 
Old 07-28-2003, 06:43 AM   #10
titanium_geek
Senior Member
 
Registered: May 2002
Location: Melbourne Australia
Distribution: it died/ macosx
Posts: 2,478

Original Poster
Rep: Reputation: 50
Ah ha! finaly it looks like I can start to regrow my hair (after pulling it all out)

just checking: the full directory for /root/cron is /home/penguin/root/cron (??)

thankyou thankyou thankyou

titanium_geek
 
Old 07-28-2003, 07:51 AM   #11
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
The example I was giving was if you were wanting the jobs to run as root. If it is to be run as another user eg yourself I would use:
/home/penguin/cron
/home/penguin/cron/jobs
/home/penguin/cron/logs

I always put the cron dir under the users home directory.
 
Old 08-01-2003, 10:28 AM   #12
titanium_geek
Senior Member
 
Registered: May 2002
Location: Melbourne Australia
Distribution: it died/ macosx
Posts: 2,478

Original Poster
Rep: Reputation: 50
yay! yay!

sadly, I just killed(ish) my linux drive... must reformat
NEVER delete things as root unless it's one thing and you must read it carefully, never just say y y y y y y to "do you wanna delete this?" because bad things happen..

ohwell

titanium_geek
 
  


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 Problems eagle683 Programming 6 07-26-2005 06:26 PM
cron problems tassinari Linux - Newbie 8 04-02-2005 10:11 PM
Problems upgrading glibc. Very Frustrated. Feel like an idiot. :confused: maruson Linux - Software 2 08-25-2004 04:34 PM
Serious /tmp problems(ack!) I'm an idiot... Flecko Slackware 13 05-29-2004 02:47 PM
CRON problems jlinden Linux - General 1 09-02-2003 02:16 PM


All times are GMT -5. The time now is 04:22 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