LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Centos 6 Crontab NOT runing (https://www.linuxquestions.org/questions/linux-server-73/centos-6-crontab-not-runing-941455/)

Ubunter 04-24-2012 06:14 AM

Centos 6 Crontab NOT runing
 
Dear all,
After moving to Centos 6, I'm detecting that my crontab is not running any way. I have copied the cron file from my old centos 5, and it's having the following:

Quote:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
HOME=/
MAILTO=my@mail.com


# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed

# run-parts
17 * * * * root run-parts /etc/cron.hourly
38 5 * * * root run-parts /etc/cron.daily
11 4 * * 0 root run-parts /etc/cron.weekly
13 2 5 * * root run-parts /etc/cron.monthly
0 0 * * * root rm -rf /tmp/*
0 0 * * * root rm -rf /var/tmp/*
0 0 * * * root cat /dev/null > ~/.mysql_history

#a2billing
0 12 * * * a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_archive_data_cront.php
0 10 21 * * a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_autorefill.php
0 * * * * a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_alarm.php
20 0 * * * a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_batch_process.php
0 0 * * * a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_bill_diduse.php
0 6 * * * a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_batch_billing.php
1 * * * * a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_notify_account.php
0 6 * * * a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_batch_billing.php
0 6 1 * * a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_subscription_fee.php
0 1 * * * a2billing php /usr/src/Star2Billing/Cronjobs/currencies_update_yahoo.php
##Simultaneous calls check
#*/2 * * * * a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_check_simult.php

#SugarCrm Schedulers
* * * * * root php /usr/src/crm; php -f cron.php > /dev/null 2>&1

#asterisk

*/2 * * * * root perl /usr/local/bin/check-failed-regs.pl

When i try to run any of these commands in shel, they are working properly, but when I try to do ./crontab, I get, i.e:
Quote:

./crontab: line 35: 0: command not found
...etc

What's going on? I'm googling into this, but all what i found is relating to install the cronie-anacron, which I already have, and up to date, and else, but nothing is working with me...

Any idea, please!!

lithos 04-24-2012 07:17 AM

Hi Ubunter

Although you didn't specify full path for your programs to get it running, you should:
- check whether your #a2billing and php are in your path (PATH=/sbin:/bin:/usr/sbin:/usr/bin)
- set full pathnames for running programs/scripts, like:
Code:

service crond status
crond (pid  4047) is running...

which php
/usr/bin/php

0 6 * * * /usr/local/a2billing /usr/bin/php  /usr/src/Star2Billing/Cronjobs/a2billing_batch_billing.php  <-- define your paths according to your system

I'm giving this examples based on CentOS 5.x system, so it should be the same on yours.

good luck

Ubunter 04-24-2012 10:41 AM

Hi lithos,

Im my OS, I have:
Quote:

service crond status
crond (pid 4871) is running...

Then the perl and the php are properly there as:

Quote:

which php
/usr/bin/php
which perl
/usr/bin/perl

But the users, root, it's the root itself, so the first lines should have no problem to get executed, as root, but it's showing also as command not found into:
Quote:

17 * * * * root run-parts /etc/cron.hourly
I have changed the command, instead of username, to user-path.. as you suggest, but it's showing:

Quote:

./crontab
./crontab: línea 19: 17: no se encontró la orden
./crontab: línea 20: 38: no se encontró la orden
./crontab: línea 21: 11: no se encontró la orden
./crontab: línea 22: 13: no se encontró la orden
./crontab: línea 23: 0: no se encontró la orden
./crontab: línea 24: 0: no se encontró la orden
./crontab: línea 25: 0: no se encontró la orden
./crontab: línea 28: 0: no se encontró la orden
./crontab: línea 29: 0: no se encontró la orden
./crontab: línea 30: 0: no se encontró la orden
./crontab: línea 31: 20: no se encontró la orden
./crontab: línea 32: 0: no se encontró la orden
./crontab: línea 33: 0: no se encontró la orden
./crontab: línea 34: 1: no se encontró la orden
./crontab: línea 35: 0: no se encontró la orden
./crontab: línea 36: 0: no se encontró la orden
./crontab: línea 37: 0: no se encontró la orden
./crontab: línea 42: a2billing.conf: no se encontró la orden
./crontab: línea 46: */2: No existe el fichero o el directorio << this file exist in the correct path...!!
./crontab: línea 50: 14: no se encontró la orden
./crontab: línea 51: a2billing.conf: no se encontró la orden
./crontab: línea 52: a2billing.conf: no se encontró la orden
./crontab: línea 53: a2billing.conf: no se encontró la orden
./crontab: línea 55: a2billing.conf: no se encontró la orden
./crontab: línea 56: a2billing.conf: no se encontró la orden
./crontab: línea 57: a2billing.conf: no se encontró la orden
./crontab: línea 58: a2billing.conf: no se encontró la orden

lithos 04-24-2012 11:43 AM

Now,
I don't know how are you trying to run crontab manually, but
first is how you edit it ?
Code:

# crontab -e
is the right way
then you copy into the file what you want.

You make sure that it's enabled at startup

And then you make sure which CRONTAB are you editing / using,
because there's a system crontab at
Code:

cat /etc/crontab 

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
## 01 * * * * root run-parts /etc/cron.hourly
## 02 4 * * * root run-parts /etc/cron.daily
## 22 4 * * 0 root run-parts /etc/cron.weekly
## 42 4 1 * * root run-parts /etc/cron.monthly

and there's ROOT's crontab
Code:

# crontab -e

MAILTO=root

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/bin:/usr/sbin:/usr/local/bin

# Run-parts
01 * * * * run-parts /etc/cron.hourly
02 4 * * * run-parts /etc/cron.daily
22 4 * * 0 run-parts /etc/cron.weekly
42 4 1 * * run-parts /etc/cron.monthly

40 0 * * * /usr/local/bin/myscript.sh
55 0 */2 * * /usr/local/bin/myscript_1.sh

good luck

Ubunter 04-24-2012 05:11 PM

Thanks again for your prompt lithos,

I have to re-edit my last post as I did the following now...

First i removed the old crontab from etc.

Then:
As I don't like to use VI, and apparently the cron is not reading from nano, I made:
Quote:

export EDITOR=nano
Then:
Quote:

crontab -e
And plced inside my cron lines...

Then:
restart the crond, and cron -l and i see all my cron..
Make tail /var/log/cron, and it seem to be all fin working...

I guess the error was coming from the nano, as i wrote the cron in /etc/crontab with nano.

But, in my mail I still getting alerts as:

Quote:

/bin/bash: a2billing: command not found
for the:
Quote:

a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_alarm.php
And others.... I don't know where I find the user path, as I create the a2billing user as:

Quote:

useradd -M -s /sbin/nologin a2billing
also getting alert for the root user:
Quote:

root perl /usr/local/bin/check-failed-regs.pl
As:
Quote:

/bin/bash: root: command not found
Really have no idea??

Thanks again for all :)

Chears!

lithos 04-25-2012 11:50 AM

Quote:

Originally Posted by Ubunter (Post 4662138)
And others.... I don't know where I find the user path, as I create the a2billing user as:

Quote:

useradd -M -s /sbin/nologin a2billing

Really you add the user with no shell login and then you want to run Cron as that user?
Code:

#a2billing
0 12 * * * a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_archive_data_cront.php
0 10 21 * * a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_autorefill.php
0 * * * * a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_alarm.php
20 0 * * * a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_batch_process.php
0 0 * * * a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_bill_diduse.php
0 6 * * * a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_batch_billing.php
1 * * * * a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_notify_account.php
0 6 * * * a2billing php /usr/src/Star2Billing/Cronjobs/a2billing_batch_billing.php

Think again why it can not work (related to above useradd).

You will best learn and solve if you know what you did wrong instead of someone writes you and you just copy/paste then.


good luck

Ubunter 04-25-2012 12:13 PM

Ok, you're write, sorry, I haven't thought about the nonlogin to run the cron...

But i just turn that crons to root, as i don't mind to run them as the user, or as root, and I still getting the same erros by mail as:
Quote:

root perl /usr/local/bin/check-failed-regs.pl
/bin/bash: root: command not found
and
Quote:

root php /usr/src/Star2Billing/Cronjobs/a2billing_check_simult.php
/bin/bash: root: command not found
Regards,

lithos 04-25-2012 03:44 PM

Hi,

well, CentOS does not have "Run As " in the ROOT's crontab, it's in "/etc/crontab"

take a look here, it will be much clearer what you're doing wrong.

Ubunter 04-26-2012 04:45 AM

Quote:

Originally Posted by lithos (Post 4662996)
Hi,

well, CentOS does not have "Run As " in the ROOT's crontab, it's in "/etc/crontab"

take a look here, it will be much clearer what you're doing wrong.

I really still lossed in this, as in ubuntu I never had such as issue with the same cron...

As noboddy I can't run the crons, as this may make me problems into the system... I have deleted the a2billing user, and add the user as: useradd -M -s /sbin/ a2billing, but still getting the same command not found error...

which i can't understand, why the root crons are not working also, as they are the default OS crons, as:
Quote:

root run-parts /etc/cron.hourly
/bin/bash: root: command not found
Which is coming by default into the OS, and I haven't played with...?!

lithos 04-26-2012 01:06 PM

Hi,

I really don't know what is the cause and I would try to do it from scratch to see if working.
BUT FIRST make a backup of your crontabs (root's and /etc)
for example when 'root' you can do:
Code:

# crontab -l >~/crontab-backup-04-2012
Then you can copy /etc/crontab:
Code:

# cp -pv /etc/crontab /etc/crontab-backup-04-2012
now after the backup, you can delete root's crontab (being user root) with
Code:

# crontab -r
then make a new crontab with
Code:

# crontab -e
and put in something to check if it's working, like create a file in some directory
Code:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# Run-parts #defaults
01 * * * * run-parts /etc/cron.hourly
02 4 * * * run-parts /etc/cron.daily
22 4 * * 0 run-parts /etc/cron.weekly
42 4 1 * * run-parts /etc/cron.monthly

# this should test the proper execution
*/1 * * * * touch /var/tmp/testfile-$(date +"%F-%H.%M")

this should create a file every minute, in the path /var/tmp and filename like "testfile-2012-04-13.00", "testfile-2012-04-13.01", "testfile-2012-04-13.02"

Then you can gradually proceed adding tasks to root's crontab.

Reuti 04-26-2012 01:16 PM

root’s crontab is not /etc/crontab. Only the latter has a six’th field for the user to be used to run this entry. Obviously it’s specified as “root”, but during execution treated like being the executing command.

Ubunter 04-27-2012 01:49 AM

Quote:

Originally Posted by lithos (Post 4663764)
Hi,

I really don't know what is the cause and I would try to do it from scratch to see if working.
BUT FIRST make a backup of your crontabs (root's and /etc)
for example when 'root' you can do:
Code:

# crontab -l >~/crontab-backup-04-2012
Then you can copy /etc/crontab:
Code:

# cp -pv /etc/crontab /etc/crontab-backup-04-2012
now after the backup, you can delete root's crontab (being user root) with
Code:

# crontab -r
then make a new crontab with
Code:

# crontab -e
and put in something to check if it's working, like create a file in some directory
Code:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# Run-parts #defaults
01 * * * * run-parts /etc/cron.hourly
02 4 * * * run-parts /etc/cron.daily
22 4 * * 0 run-parts /etc/cron.weekly
42 4 1 * * run-parts /etc/cron.monthly


Code:

Until here all was fin, and now errors...


       
Quote:

       
       
               
       
       

                       

                       
                                # this should test the proper execution
*/1 * * * * touch /var/tmp/testfile-$(date +"%F-%H.%M")
                       
                       

               


With this I got the mail as:
Quote:

touch /var/tmp/testfile-$(date +"...
/bin/bash: -c: line 0: unexpected EOF while looking for matching `"'
/bin/bash: -c: line 1: syntax error: unexpected end of file
I tired to edit the test line as:
Quote:

*/1 * * * * touch /var/tmp/testfile-$(date +`date +%Y-%m-%d`)
But still getting the same error, so, no matter, as it's just syntax error, I remove it...


Quote:

Then you can gradually proceed adding tasks to root's crontab.
When I add for example:
Quote:

14 * * * * root mysqlcheck -a -r -o -uroot -pPassword DB-name
I get:
Quote:

/bin/bash: root: command not found
And same for:
Quote:

0 0 * * * root rm -rf /tmp/*
/bin/bash: root: command not found

Regards,

Reuti 04-27-2012 02:12 AM

Did you edit /etc/crontab or root’s crontab? Also please check man 5 crontab as the “%” has special meaning inside crontab and needs a special coding.

lithos 04-27-2012 03:08 AM

Quote:

Originally Posted by Ubunter (Post 4664212)
With this I got the mail as:
Quote:

touch /var/tmp/testfile-$(date +"...
/bin/bash: -c: line 0: unexpected EOF while looking for matching `"'
/bin/bash: -c: line 1: syntax error: unexpected end of file
I tired to edit the test line as:

Quote:

*/1 * * * * touch /var/tmp/testfile-$(date +`date +%Y-%m-%d`)
But still getting the same error, so, no matter, as it's just syntax error, I remove it...

Yes, it's a syntax error, but at least it's working
Code:

*/1 * * * * touch /var/tmp/testfile-$(date +`date +%Y-%m-%d`)

Should be:
*/1 * * * * touch /var/tmp/testfile-$(date +"\%Y-\%m-\%d")

and nothing else (because the format of the command needs proper syntax)

You can read more about Crontab. It will be helpful.

Now onto your second problem with "command not found"
Quote:

Originally Posted by Ubunter (Post 4664212)
And same for:
Code:

:
0 0 * * * root rm -rf /tmp/*
/bin/bash: root: command not found


It really can not be found because it's not properly set in crontab !

Code:

0 0 * * * root rm -rf /tmp/*
this syntax CAN ONLY be used in "/etc/crontab"

and not in the root's or any other user's crontab (which you edit with "crontab -e")!

The format in user's crontab CANNOT contain the column with the username and command to execute, because it's meant to run as the user who created its own crontab (with "crontab -e").

Now try please not putting the username in crontab just the command (this is the way to do it) otherwise you can use (in your root's crontab) sudo command to become other user and execute commands.

Good luck

Ubunter 04-30-2012 03:56 AM

Quote:

The format in user's crontab CANNOT contain the column with the username and command to execute, because it's meant to run as the user who created its own crontab (with "crontab -e").

Now try please not putting the username in crontab just the command (this is the way to do it) otherwise you can use (in your root's crontab) sudo command to become other user and execute commands.
Thanks again lithos,
I'm doing and testing this since 2 days, the root crontab seem to be working, unless today i got this report by mail:
Quote:

/etc/cron.daily/mlocate.cron:

/usr/bin/updatedb: `/var/lib/mlocate/mlocate.db' is locked (probably by an earlier updatedb)
But as you said, i have re-edit the /etc/crontab, and put my commands without the username, as:
Quote:

0 0 * * * rm -rf /tmp/*
0 0 * * * rm -rf /var/tmp/*
0 0 * * * cat /dev/null > ~/.mysql_history
*/1 * * * * touch /var/tmp/testfile-$(date +"\%Y-\%m-\%d")
But this last one still not working nothing, the test is not running, and I can't find any report in the log for this crontab...

The unique way, which I got it to work is to run the crons without user, into the root crontab as crontab -e I add the lines, and now, i see there log as running into the root, but not as custom /etc/crontab... I don't know if this is correct, it's working, but it's correct?


All times are GMT -5. The time now is 05:52 PM.