LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 09-28-2008, 03:33 AM   #1
ksmatthews
Member
 
Registered: Aug 2008
Posts: 86

Rep: Reputation: 15
Question crontab problems


Good Morning,

I am new to Linux and so still have a lot to learn ...

I have a file called crontab in /etc/crontab, and I can edit it using
vi /etc/crontab.

I have an entry, as follows ...

0/1 * * * * ~/public_html/swordfish/call_centre/cron/auto_report_fred.sh

BUT cron does NOT run it. Why not ?

Another problem is when I use the crontab command 'crontab -e' to edit the crontab file, it creates a new one and does not see my manual changes.

I have also tried create a crontab file like this 'crontab <filename>'
but that reoprts the following error ....

no crontab for root - using an empty one

How do I use crontab correctly ??

regards,

Steven M
 
Old 09-28-2008, 03:44 AM   #2
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Try using the full path rather than ~

What do you mean by manual changes?

Last edited by billymayday; 09-28-2008 at 03:46 AM.
 
Old 09-28-2008, 07:13 AM   #3
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 47
Moin,

the /etc/crontab you use is a system wide crontab file and has a special syntax, which differs from "ordinary" user crontab files:
Code:
# /etc/crontab
Min Hour MDay Month WDay User Command
# user crontab (usually in /var/spool/cron/tabs)
Min Hour MDay Month WDay Command
When you edit a crontab file using "crontab -e" (which I would prefer, it's not sure that a manual editing of a crontab file is noticed by the cron daemon), then you edit the user's crontab, not the system's file.

Besides that: You should keep in mind, that the cron daemon doesn't know the environment, which is defined when you log in. You should use absolute path names every time and define all environment variables you use in your script.

Jan
 
Old 09-29-2008, 09:21 AM   #4
vicjalan
LQ Newbie
 
Registered: Sep 2008
Location: Altanta, GA
Distribution: RHEL 5, Fedora 8, Fedora 9
Posts: 9

Rep: Reputation: 1
Similar Problem...

Hi all,

I have a similar problem that I don't seem to understand. My /etc/crontab looks like:


Code:
*/5 * * * * root /usr/local/mrtg-2/bin/mrtg /home/mrtg/cfg/mdfbbsw01/mdfbbsw01.cfg --logging /var/log/mrtg.log

This should make it so that mrtg runs every 5 minutes, however the cron job doesn't even run at all. When I look at the cron logfile, there are no errors or signs that it even tried to execute that line. It's like if it didn't exist.

I've tried scheduling a simple shell script that just creates a folder to see if the issue was mrtg related, but I nothing I add to crontab executes.

I tried editing the /etc/crontab manually and via "crontab -e". I get the same results. Am I missing anything?

BTW this is on Fedora 8.

Thanks in advance,
 
Old 09-29-2008, 01:49 PM   #5
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 47
Moin,

I think your problem is another. Are you sure that your cron is running? Are you (and root) are allowed to use cron?

Jan
 
Old 09-29-2008, 02:30 PM   #6
AuroraCA
Member
 
Registered: Jul 2008
Location: Northern CA USA
Distribution: Ubuntu, Slackware, Gentoo, Fedora, Red Hat, Puppy Linux
Posts: 370

Rep: Reputation: 35
Original Code:
Quote:
0/1 * * * * ~/public_html/swordfish/call_centre/cron/auto_report_fred.sh
Try this:

Code:
0/1 * * * * sh (pathname)/public_html/swordfish/call_centre/cron/auto_report_fred.sh
or

Code:
0/1 * * * * . (pathname)/public_html/swordfish/call_centre/cron/auto_report_fred.sh
You are running a shell program and depending upon the permissions set for the file you need to make sure that it executes a shell to run it.

Replace (pathname) with the full pathname of the file.

Last edited by AuroraCA; 09-29-2008 at 02:36 PM.
 
Old 09-29-2008, 07:20 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
As a general point, if cron has a problem running a job, it usually sends a mail to the crontab's owner and/or root. Just use the cli mailx program to check.
 
Old 09-30-2008, 07:39 AM   #8
vicjalan
LQ Newbie
 
Registered: Sep 2008
Location: Altanta, GA
Distribution: RHEL 5, Fedora 8, Fedora 9
Posts: 9

Rep: Reputation: 1
Cron is running..

Yes, Cron is running (I'm logged in as root whenever I set up a cron job anyway). My scripts have 0775 permissions.

Quote:
As a general point, if cron has a problem running a job, it usually sends a mail to the crontab's owner and/or root. Just use the cli mailx program to check.
This is true, but Cron has to attempt to run the job first. If it doesn't even know it needs to run it, then no emails will be sent out.

When I look at the var/logs/cron all I see is the stuff that runs hourly and daily being executed, nothing about what I set up.

Code:
Sep 30 06:01:01 serv1 CROND[28214]: (root) CMD (run-parts /etc/cron.hourly)
Sep 30 07:01:01 serv1 CROND[13535]: (root) CMD (run-parts /etc/cron.hourly)
Sep 30 08:01:01 serv1 CROND[31307]: (root) CMD (run-parts /etc/cron.hourly)
 
Old 09-30-2008, 01:27 PM   #9
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 47
Moin,

hm, then you should check:
1. Are there entries from cron in the system's messages or warn files?
2. Is cron running as root? Has cron the permissions to read the crontab files?
3. Like I already said: Are there restrictions defined in the cron/allow or cron/deny files?
4. Is cron running in a chroot environment - does he read his configuration from another directory?
5. Does a crontab job (a simple shell script like "/bin/ls /etc") run if you create a cron job for another user (use "crontab -e")?
6. Is a security extension like SELinux active on your system?

The questions may be silly, but somewhere you have to start looking for an answer

Jan

Last edited by jan61; 09-30-2008 at 04:10 PM.
 
Old 09-30-2008, 03:27 PM   #10
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Using "crontab -e" as root, add a line
Code:
*/5 * * * * /usr/local/mrtg-2/bin/mrtg /home/mrtg/cfg/mdfbbsw01/mdfbbsw01.cfg --logging /var/log/mrtg.log
Note the deletion of the username "root"

Perhaps this thread will shed a bit of light on things

http://www.linuxquestions.org/questi...rontab-382120/

Last edited by billymayday; 09-30-2008 at 03:29 PM.
 
Old 10-01-2008, 09:59 AM   #11
vicjalan
LQ Newbie
 
Registered: Sep 2008
Location: Altanta, GA
Distribution: RHEL 5, Fedora 8, Fedora 9
Posts: 9

Rep: Reputation: 1
Thanks all for you help, I got it working

Whenever I would do crontab -e, crontab would not save any of the commands I was typing, but I found an article where they suggested making the editor = vi. Once I did that I was able to save my contents and crontab is now working as expected.

Thanks again.
 
Old 11-06-2008, 09:43 AM   #12
TonyRad
LQ Newbie
 
Registered: Nov 2008
Posts: 1

Rep: Reputation: 0
I'm running into a similar problem as well and have tried several ways to fix it but just can't seem to get this working right.

My crontab seems to be working as I can enter in a line to append to a file, create a file, etc. However, my line for MRTG doesn't seem to work. I can copy and paste that exact command into my prompt and it runs but I just can't get it to run every 5 minutes.

Code:
*/5 * * * * /usr/bin/mrtg /var/www/html/cfg_files/CityCore.cfg --logging /var/log/mrtg/mrtg.log
I have tried editing via 'vi /etc/crontab', crontab -e (on root account and nagios account). I have tried putting a user in the crontab entry. I have tried adding '.' and 'sh' into the entry. I have also verified that the permissions to the needed files are all as they should be. By everything I am seeing this should be working without a problem.

I have also tried to specify the exact time it should run and it still doesn't. Is there something else I am missing??

Thanks!
Tony
 
Old 11-06-2008, 01:35 PM   #13
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 47
Moin,

is there a mail message from the cron daemon for the user, for which you installed the cron job? Normally the cron writes a mail containing errors and stdout from your jobs.

A possible reason: crontab jobs do not get the same environment as logged in users. Probably an environment variable is missing.

Jan
 
Old 11-07-2008, 08:44 AM   #14
vicjalan
LQ Newbie
 
Registered: Sep 2008
Location: Altanta, GA
Distribution: RHEL 5, Fedora 8, Fedora 9
Posts: 9

Rep: Reputation: 1
Unfortunately I never to work using the /etc/crontab file. I had to use crontab -e. For some reason editing the user's crontab file manually would not work for me either.

When you use crontab -e to add that entry, have to checked in /var/spool/cron to see if that user's crontab has been created? If so, have you check to make sure that whatever you entered in the vi editor actually got saved.

If you've modified the user's crontab manually for whatever reason, use crontab -e to remove whatever entry you made to the file manually, save and quit. Then try to add your entry again using crontab -e.

This is what worked for me a few days ago when an entry would not work for me.
 
Old 11-12-2008, 09:28 AM   #15
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
always use crontab -e

don't edit it directly.
or the cron daemon doesn't know it's been changed.
also it checks for errors.
 
  


Reply



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
crontab problems charlo.navidad Linux - Software 4 03-19-2007 09:46 AM
Crontab Problems RemusX2 Linux - Software 5 07-13-2006 10:08 AM
Problems with crontab haddad Linux - Software 4 01-18-2006 01:09 PM
problems with crontab p.gaic Linux - Software 7 07-25-2005 05:36 AM
crontab problems dshafi Linux - General 1 08-19-2004 02:51 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:27 AM.

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