LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Problem with CRON Help.. (https://www.linuxquestions.org/questions/linux-newbie-8/problem-with-cron-help-902743/)

conflicker 09-13-2011 04:56 AM

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

colucix 09-13-2011 05:01 AM

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?

conflicker 09-13-2011 05:14 AM

Quote:

Originally Posted by colucix (Post 4470448)
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.

colucix 09-13-2011 05:27 AM

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

conflicker 09-13-2011 05:49 AM

Quote:

Originally Posted by colucix (Post 4470466)
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.

colucix 09-13-2011 06:28 AM

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)

conflicker 09-13-2011 11:07 PM

Quote:

Originally Posted by colucix (Post 4470503)
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?

colucix 09-14-2011 12:36 AM

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

conflicker 09-14-2011 02:31 AM

Quote:

Originally Posted by colucix (Post 4471157)
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?

colucix 09-14-2011 02:03 PM

Quote:

Originally Posted by conflicker (Post 4471223)
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 (Post 4471223)
Is there a way to upgrade and downgrade the nice command?

Sorry, I don't understand this question. Could you elaborate a bit, please?

conflicker 09-14-2011 11:52 PM

Quote:

Originally Posted by colucix (Post 4471733)
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?

colucix 09-15-2011 01:20 AM

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.

conflicker 09-15-2011 02:20 AM

Quote:

Originally Posted by colucix (Post 4472147)
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.

colucix 09-15-2011 02:47 AM

Quote:

Originally Posted by conflicker (Post 4472199)
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.

conflicker 09-16-2011 05:21 AM

Quote:

Originally Posted by colucix (Post 4472214)
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..


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