Cronjob error

Asked by tearsforhari

Hello--

I am getting emailed as root the following error:

/etc/cron.daily/ntpdate:
run-parts: failed to exec /etc/cron.daily/ntpdate: Exec format error
run-parts: /etc/cron.daily/ntpdate exited with return code 1

But when I do the following command, I do not find an active job:

> crontab -l

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
45 23 23 6 * /sbin/shutdown -r +5

Where is the error originating from? Could someone have implemented a job someone else?

Thank You.

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
tearsforhari
Solved:
Last query:
Last reply:
Revision history for this message
tearsforhari (tearsforhari) said :
#1

Here's my cron.daily file:

" ============================================================================
" Netrw Directory Listing (netrw v143)
" /etc/cron.daily
" Sorted by name
" Sort sequence: [\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$
" Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:exec
" ============================================================================
../
apport*
apt*
aptitude*
bsdmainutils*
dpkg*
exim4-base*
logrotate*
man-db*
mlocate*
ntp*
ntpdate*
passwd*
popularity-contest*
standard*
update-notifier-common*
.placeholder
.swp

Revision history for this message
tearsforhari (tearsforhari) said :
#2

Sorry that's my directory listing.

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#3

What are you trying to cron? With what frequency?

Thanks

Revision history for this message
tearsforhari (tearsforhari) said :
#4

Nothing. I have not implemented any cronjobs. It could be that someone else trued to implement one; but it is not listed in the cronjob -l listing. I do not know where that error is stemming from. I suppose I could delete ntpdate and get rid of the error. But there should be a reason for the error.

Revision history for this message
Manfred Hampl (m-hampl) said :
#5

What is the output of

ls -l /etc/cron.daily/ntpdate
file /etc/cron.daily/ntpdate

Revision history for this message
tearsforhari (tearsforhari) said :
#6

> ls -l /etc/cron.daily/ntpdate
-rwxr-xr-x 1 root root 37 Jun 6 2014 /etc/cron.daily/ntpdate

> file /etc/cron.daily/ntpdate
/etc/cron.daily/ntpdate: ASCII text

Revision history for this message
tearsforhari (tearsforhari) said :
#7

Wondering if the default shell for crontab should be set to bash for ntpdate...?

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#8

Is this on a desktop OS? If so, you can use gnome-schedule as a GUI to cron.

Revision history for this message
Manfred Hampl (m-hampl) said :
#9

What is the output of

cat /etc/cron.daily/ntpdate

Revision history for this message
tearsforhari (tearsforhari) said :
#10

No server edition (12.04.5). I'm just trying to get rid of the system cron error. The cronjob is not being initiated by me. I noted on my other servers that ntpdate is missing. Is it really necessary?

Revision history for this message
Manfred Hampl (m-hampl) said :
#11

see https://help.ubuntu.com/community/UbuntuTime for information about ntp and ntpdate

What are the contents

cat /etc/cron.daily/ntpdate

Revision history for this message
tearsforhari (tearsforhari) said :
#12

> cat /etc/cron.daily/ntpdate
ntpdate ntp.ubuntu.com pool.ntp.org

Revision history for this message
tearsforhari (tearsforhari) said :
#13

The contents of the file look strange to me. I thought that there would be a script.

Revision history for this message
Manfred Hampl (m-hampl) said :
#14

on Unix systems the first line of a script should indicate the program used for running that script ("shebang").
This apparently is missing here.

Try editing that script (e.g. with the command "sudo gedit /etc/cron.daily/ntpdate" and add

#!/bin/sh

as very first line similar to what is shown in https://help.ubuntu.com/community/UbuntuTime#Command_Line_ntpdate

Revision history for this message
tearsforhari (tearsforhari) said :
#15

Yes, adding shebang solved the problem of reading the script. But now it apparent that there is some other problem with ntpdate:

> ntpdate ntp.ubuntu.com pool.ntp.org
/etc/cron.daily/ntpdate:
18 Jul 06:27:09 ntpdate[62068]: the NTP socket is in use, exiting
run-parts: /etc/cron.daily/ntpdate exited with return code 1

Revision history for this message
tearsforhari (tearsforhari) said :
#16

Well, I added a -u and ntpdate is working now:

> ntpdate -u ntp.ubuntu.com pool.ntp.org

There is a file in cron.daily called ntp. I wonder if this is redundant, and if I should remove ntp or ntpdate?

> cat ntp
#!/bin/sh

# The default Debian ntp.conf enables logging of various statistics to
# the /var/log/ntpstats directory. The daemon automatically changes
# to a new datestamped set of files at midnight, so all we need to do
# is delete old ones, and compress the ones we're keeping so disk
# usage is controlled.

statsdir=$(cat /etc/ntp.conf | grep -v '^#' | sed -n 's/statsdir \([^ ][^ ]*\)/\1/p')

if [ -n "$statsdir" ] && [ -d "$statsdir" ]; then
        # only keep a week's depth of these
        find "$statsdir" -type f -mtime +7 -exec rm {} \;

        # compress whatever is left to save space
        cd "$statsdir"
        ls loopstats.???????? peerstats.???????? > /dev/null 2>&1
        if [ $? -eq 0 ]; then
                # Note that gzip won't compress the file names that
                # are hard links to the live/current files, so this
                # compresses yesterday and previous, leaving the live
                # log alone. We supress the warnings gzip issues
                # about not compressing the linked file.
                gzip --best --quiet loopstats.???????? peerstats.????????
                return=$?
                case $return in
                    2)
                        exit 0 # squash all warnings
                        ;;
                    *)
                        exit $return # but let real errors through
                        ;;
                esac
        fi
fi

Revision history for this message
tearsforhari (tearsforhari) said :
#17

Ok...worked lastnight. But why is it the only progrem in /etc/cron.daily that emailed me the following and how to turn off the email?

/etc/cron.daily/ntpdate:
19 Jul 06:46:41 ntpdate[10926]: adjust time server 129.6.15.30 offset -0.000695 sec