LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-13-2011, 05:56 AM   #1
conflicker
Member
 
Registered: Sep 2011
Posts: 89

Rep: Reputation: Disabled
Question Problem with CRON Help..


Hi everybody..I'm a newbie of this cron...
I already have a crontab but the cron is not executing the schedule..

I don't what are those things need to consider in order for the cron to run perfectly..

is there configuration,package need to install before to use this cron...please help..
 
Old 09-13-2011, 06:01 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
If you have a crontab, all the needed software should be there. Is the cron daemon running?
Code:
/etc/init.d/crond status
Please, can you show us your current crontab?
 
1 members found this post helpful.
Old 09-13-2011, 06:14 AM   #3
conflicker
Member
 
Registered: Sep 2011
Posts: 89

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by colucix View Post
If you have a crontab, all the needed software should be there. Is the cron daemon running?
Code:
/etc/init.d/crond status
Please, can you show us your current crontab?
this is my crontab
0 * * * * cd /home/lotw/public_html/MOTD; make
is there any configuration need to setup? cause I see many crontab. I'm just wondering how the system execute this files and what is the contrab being executed first.
 
Old 09-13-2011, 06:27 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Linux usually has a system crontab /etc/crontab to run jobs on a hourly, daily, weekly and monthly basis. In addition every user has its own crontab (that one you edit using crontab -e) and everyone is allowed to have it, unless the username is listed in /etc/cron.deny. Regarding the crontab being executed first, the order is that one dictated by the time specification in the crontab itself. It's the cron daemon that takes care of doing things in chronological sequence.

Regarding your issue you need to check:
1. if the cron daemon is running
2. if your username is listed in /etc/cron.deny
3. if the system logs (e.g. /var/log/cron) report your cron job running at the specified time
4. if there is some message from the cron daemon in your mail box (use the mail command).
 
1 members found this post helpful.
Old 09-13-2011, 06:49 AM   #5
conflicker
Member
 
Registered: Sep 2011
Posts: 89

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by colucix View Post
Linux usually has a system crontab /etc/crontab to run jobs on a hourly, daily, weekly and monthly basis. In addition every user has its own crontab (that one you edit using crontab -e) and everyone is allowed to have it, unless the username is listed in /etc/cron.deny. Regarding the crontab being executed first, the order is that one dictated by the time specification in the crontab itself. It's the cron daemon that takes care of doing things in chronological sequence.

Regarding your issue you need to check:
1. if the cron daemon is running
2. if your username is listed in /etc/cron.deny
3. if the system logs (e.g. /var/log/cron) report your cron job running at the specified time
4. if there is some message from the cron daemon in your mail box (use the mail command).
Sir..I try to follow the steps that gave me.
for step No. 1, I check the status of the crond, and it says that it is running.
for step No. 2, there is no cron.deny exist in the system but instead of cron.d.. I guess its the same, and when i open the directory there is no "root" in the list.
for step No. 3, I don't exactly understand on how to do this step..but i try to open the example directory, but it seems the directory is not exist.
and for the last step, I type mail on the CLI and it says that "No mail for root".

I think I have problem with the step 3.
 
Old 09-13-2011, 07:28 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Depending on your Linux OS (which is it?) you might not have the /var/log/cron file. As root you can do:
Code:
grep -E -i "CROND|CMD" /var/log/*
to find out where the cron daemon stores its messages. Here is an example from my /var/log/cron on CentOS 6:
Code:
# tail /var/log/cron
Sep 13 12:50:01 ocean-4 CROND[20740]: (root) CMD (/usr/lib/sa/sa1 -S DISK 1 1)
Sep 13 13:00:01 ocean-4 CROND[20772]: (root) CMD (/usr/lib/sa/sa1 -S DISK 1 1)
Sep 13 13:00:01 ocean-4 CROND[20774]: (root) CMD (/home/skiron/download_skiron.sh $(date +%Y%m%d))
Sep 13 13:01:01 ocean-4 CROND[20787]: (root) CMD (run-parts /etc/cron.hourly)
Sep 13 13:01:01 ocean-4 run-parts(/etc/cron.hourly)[20787]: starting 0anacron
Sep 13 13:01:02 ocean-4 anacron[20798]: Anacron started on 2011-09-13
Sep 13 13:01:02 ocean-4 run-parts(/etc/cron.hourly)[20800]: finished 0anacron
Sep 13 13:01:02 ocean-4 anacron[20798]: Normal exit (0 jobs run)
Sep 13 13:10:01 ocean-4 CROND[21453]: (root) CMD (/usr/lib/sa/sa1 -S DISK 1 1)
Sep 13 13:20:01 ocean-4 CROND[21500]: (root) CMD (/usr/lib/sa/sa1 -S DISK 1 1)
Here the third line is from the root's crontab entry:
Code:
0 13 * * * /home/skiron/download_skiron.sh $(date +\%Y\%m\%d)
 
Old 09-14-2011, 12:07 AM   #7
conflicker
Member
 
Registered: Sep 2011
Posts: 89

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by colucix View Post
Depending on your Linux OS (which is it?) you might not have the /var/log/cron file. As root you can do:
Code:
grep -E -i "CROND|CMD" /var/log/*
to find out where the cron daemon stores its messages. Here is an example from my /var/log/cron on CentOS 6:
Code:
# tail /var/log/cron
Sep 13 12:50:01 ocean-4 CROND[20740]: (root) CMD (/usr/lib/sa/sa1 -S DISK 1 1)
Sep 13 13:00:01 ocean-4 CROND[20772]: (root) CMD (/usr/lib/sa/sa1 -S DISK 1 1)
Sep 13 13:00:01 ocean-4 CROND[20774]: (root) CMD (/home/skiron/download_skiron.sh $(date +%Y%m%d))
Sep 13 13:01:01 ocean-4 CROND[20787]: (root) CMD (run-parts /etc/cron.hourly)
Sep 13 13:01:01 ocean-4 run-parts(/etc/cron.hourly)[20787]: starting 0anacron
Sep 13 13:01:02 ocean-4 anacron[20798]: Anacron started on 2011-09-13
Sep 13 13:01:02 ocean-4 run-parts(/etc/cron.hourly)[20800]: finished 0anacron
Sep 13 13:01:02 ocean-4 anacron[20798]: Normal exit (0 jobs run)
Sep 13 13:10:01 ocean-4 CROND[21453]: (root) CMD (/usr/lib/sa/sa1 -S DISK 1 1)
Sep 13 13:20:01 ocean-4 CROND[21500]: (root) CMD (/usr/lib/sa/sa1 -S DISK 1 1)
Here the third line is from the root's crontab entry:
Code:
0 13 * * * /home/skiron/download_skiron.sh $(date +\%Y\%m\%d)
Sir if found it on /var/log/cron:
Sep 11 05:00:01 host crond[13526]: (root) CMD (cd /home/lotw/public_html/MOTD; make)
and the latest is Sep 13 20:00:01 host2 crond[8430]: (root) CMD (cd /home/lotw/public_html/MOTD; make)
is it good or bad?

Last edited by conflicker; 09-14-2011 at 12:36 AM.
 
Old 09-14-2011, 01:36 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
It's good. At least the cron job is executed. Now you should check where the problem is and try to catch the standard output and the standard error from the job. Try to redirect them to a file so that you can check it later:
Code:
0 * * * * cd /home/lotw/public_html/MOTD; make >> /root/crontab.log 2>&1
 
1 members found this post helpful.
Old 09-14-2011, 03:31 AM   #9
conflicker
Member
 
Registered: Sep 2011
Posts: 89

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by colucix View Post
It's good. At least the cron job is executed. Now you should check where the problem is and try to catch the standard output and the standard error from the job. Try to redirect them to a file so that you can check it later:
Code:
0 * * * * cd /home/lotw/public_html/MOTD; make >> /root/crontab.log 2>&1
Thank you sir. I already found out why my crontab command is not working...
But i have some weird stuff happen here..The command in the crontab is perfectly working when i tried to copy and paste it on the CLI...

do you have any idea about this sir..?

Is there a way to upgrade and downgrade the nice command?

Last edited by conflicker; 09-14-2011 at 06:04 AM.
 
Old 09-14-2011, 03:03 PM   #10
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by conflicker View Post
But i have some weird stuff happen here..The command in the crontab is perfectly working when i tried to copy and paste it on the CLI...

do you have any idea about this sir..?
What's weird stuff? Maybe the make command uses some environment variables that are normally assigned by interactive shells (e.g. by sourcing the $HOME/.bashrc or $HOME/.bash_profile configuration files). Take in mind that the crontab starts a non-interactive shell, unless you explicitly open a new shell session using the -l option. To do this put the commands in a script and use
Code:
#!/bin/bash -l
as sha-bang or execute the script using:
Code:
0 * * * * bash -l /path/to/my_script.sh
Quote:
Originally Posted by conflicker View Post
Is there a way to upgrade and downgrade the nice command?
Sorry, I don't understand this question. Could you elaborate a bit, please?
 
Old 09-15-2011, 12:52 AM   #11
conflicker
Member
 
Registered: Sep 2011
Posts: 89

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by colucix View Post
What's weird stuff? Maybe the make command uses some environment variables that are normally assigned by interactive shells (e.g. by sourcing the $HOME/.bashrc or $HOME/.bash_profile configuration files). Take in mind that the crontab starts a non-interactive shell, unless you explicitly open a new shell session using the -l option. To do this put the commands in a script and use
Code:
#!/bin/bash -l
as sha-bang or execute the script using:
Code:
0 * * * * bash -l /path/to/my_script.sh
Sorry, I don't understand this question. Could you elaborate a bit, please?
Sir, what I'am trying to do is to convert .gsm file to .mp3, and that is the crontab command supposed to do. this is the code that i am talking:
Code:
0 * * * * cd /home/lotw/public_html/MOTD; make >> /root/crontab.log 2>&1
When I used to type the command manually on the COMMAND LINE INTERFACE, the code is perfectly working. But if the code is executed by cron base on specified time, it returns me an error.
That is the weird thing. The cron is executing the same command that i used to type on the CLI, but it is getting an error, the error is:
Code:
make: *** No rule to make target `31 Aug 2021 test3.mp3', needed by `mp3'.  Stop.
I'm just confused, the cron command and the command that I used to type on the CLI is perfectly the same, and the command is converting the same file. Both command should return the same result.

I'm just wondering if it is the version of daemon or something like that. Cause I have two different server running the same application. The old server is executing the command perfectly, even it is executed by cron or typed it manually on the CLI, overall it is fine working. But on the new server it turns me the error above. How to determine the version of daemon?
 
Old 09-15-2011, 02:20 AM   #12
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
To find out which version of the cron daemon you have, you can try to determine which package owns the /usr/sbin/crond executable. On a RPM based system you can try
Code:
rpm -qf /usr/sbin/crond
on a DEB based system:
Code:
dpkg -S /usr/sbin/crond
then gather information for that specific package. Anyway, I don't think it is a problem with the version of cron. Rather it's weird that a target has a date in its name and that date is in the future. How is it computed? Does the Makefile computes the date by itself?

I still suggest to put the command line in a script and execute it by means of bash -l to see if it is a problem with the login environment.
 
Old 09-15-2011, 03:20 AM   #13
conflicker
Member
 
Registered: Sep 2011
Posts: 89

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by colucix View Post
To find out which version of the cron daemon you have, you can try to determine which package owns the /usr/sbin/crond executable. On a RPM based system you can try
Code:
rpm -qf /usr/sbin/crond
on a DEB based system:
Code:
dpkg -S /usr/sbin/crond
then gather information for that specific package. Anyway, I don't think it is a problem with the version of cron. Rather it's weird that a target has a date in its name and that date is in the future. How is it computed? Does the Makefile computes the date by itself?

I still suggest to put the command line in a script and execute it by means of bash -l to see if it is a problem with the login environment.
The date will not matter, It's just a file name. The Makefile will look for all .gsm file in the directory and convert it into .wav using sox and the converted wav file will be converted into .mp3 using lame, that is how the Makefile do.

I try to execute the command from a bash file, and it is working..no error.

Last edited by conflicker; 09-15-2011 at 03:38 AM.
 
Old 09-15-2011, 03:47 AM   #14
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by conflicker View Post
I try to execute the command from a bash file, and it is working..no error.
So maybe it was a problem with the PATH environment variable, since cron has a very limited environment where PATH is /bin:/usr/bin. Using bash -l should have sourced the configuration files that provide a complete (login) environment.
 
Old 09-16-2011, 06:21 AM   #15
conflicker
Member
 
Registered: Sep 2011
Posts: 89

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by colucix View Post
So maybe it was a problem with the PATH environment variable, since cron has a very limited environment where PATH is /bin:/usr/bin. Using bash -l should have sourced the configuration files that provide a complete (login) environment.
I already got the solution for this problem. The only reason why cron turns me an error because I was not able to include the path of the make. It should be like:
Code:
0 * * * * cd /home/lotw/public_html/MOTD; path/of/make >> /root/crontab.log 2>&1
Everything is fine working now..Thank sir for the replies..
 
  


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
Strange Cron directories: /var/spool/cron/cron.GfqqGO Woodsman Slackware 4 05-11-2011 03:37 PM
cron.hourly cron.weekly cron.monthly and 0anacron. Are they necessary? glore2002 Debian 2 09-30-2009 09:57 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U SUSE / openSUSE 11 01-04-2007 02:57 AM
Can any one plz explain why/what for cron.d, cron.daily, cron.weekly etc are there. mavinashbabu Linux - Newbie 4 09-21-2006 02:50 PM


All times are GMT -5. The time now is 01:01 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration