LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Cron Job Error Show the Following 24: bad minute (http://www.linuxquestions.org/questions/programming-9/cron-job-error-show-the-following-24-bad-minute-4175477170/)

JockVSJock 09-14-2013 10:26 PM

Cron Job Error Show the Following 24: bad minute
 
Currently running Ubuntu 12.04 LTS 64-bit with 3.5.0-28-generic for the kernel. This is all as a guest in VirtualBox 4.2.18.

I'm trying to setup a cronjob thru crontab under root account and continue to get the following error when trying to save it.

The goal of the cronjob is to run apt-get commands to update the system without me having to do anything.

Here is the error message

Code:


"/tmp/crontab.iuvXOC/crontab":24: bad minute
errors in crontab file, can't install.

Here is the cronjob

Code:

00 20 * * * root (apt-get update && apt-get -y -d upgrade) > /var/log/aptupdate.log

apt-get clean
>/dev/null 2>&1

I found this example to test the syntax for cron and here is the output from that
Code:

root@ubuntu64vm:/var/log# cat -v /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

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

# m h dom mon dow user        command
17 *        * * *        root    cd / && run-parts --report /etc/cron.hourly
25 6        * * *        root        test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6        * * 7        root        test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6        1 * *        root        test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

By chance, the syntax color changes to green if I replace the leading zero from 0 to :

However when I try to back out of vim, I still get the same error message.

druuna 09-15-2013 02:05 AM

Quote:

Originally Posted by JockVSJock (Post 5027825)
Here is the error message

Code:


"/tmp/crontab.iuvXOC/crontab":24: bad minute
errors in crontab file, can't install.

Here is the cronjob

Code:

00 20 * * * root (apt-get update && apt-get -y -d upgrade) > /var/log/aptupdate.log

apt-get clean
>/dev/null 2>&1


All the entries in cron need to be a single line and need to start with a time indicator. The only exception is the (possible) header, which may contain environment information (PATH=, SHELL= etc).

The bold part in the above is not legal and that were the error comes from.

Have a look at this:
Code:

00 20 * * * root (apt-get update && apt-get -y -d upgrade) > /var/log/aptupdate.log ; apt-get clean >/dev/null 2>&1
Unless the command is rather simple, I personally don't like using (complicated) one-lines in cron. The long lines become unreadable, some characters need to be escaped (they are special seen from cron's perspective) and environment settings are harder to manipulate.

When the entry becomes more complicated I tend to create a script and call that script from cron.

JockVSJock 09-15-2013 01:57 PM

Putting it all on one line fixed it.

thanks


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