piman1947
Posts: 19
Joined: Wed Apr 02, 2014 4:05 am

cron job not being run

Wed Jun 26, 2019 9:04 pm

I am attempting to learn how to use cron on the raspberry Pi. I ran the crontab -e
command and added the line:
"
5 * * * * date >> /home/pi/testing_cron

which I believe should run the date command every hour at 5 minutes past the hour
and then append the date to the file /home/pi/testing_cron. This NOT happening.

The documentation I am following says
that the "cron" or "syslog" file in the "/var/log directory will contain the log of
executed cron entries. The "cron" file contains the line "myDevices agent cron job"
while the "syslog" file contains the 2 lines:

Jun 26 20:05:02 raspberrypi CRON[26456]: (root) CMD (/etc/myDevices/crontab.sh)
Jun 26 20:05:02 raspberrypi CRON[26448]: (CRON) info (No MTA installed, discarding output)

which seem to be added to the file every minute.

Can anyone explain why the cronjob is not being run and what
the error message in the "syslog" file means. I'm guessing that the error message in
the second line is causing the problem but since this is my first time using the
cron, it is only a guess. Any help will be greatfully appreciated.

LTolledo
Posts: 1534
Joined: Sat Mar 17, 2018 7:29 am

Re: cron job not being run

Wed Jun 26, 2019 9:39 pm

have you made your script "executable"

check out how to use:

Code: Select all

chmod
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

W. H. Heydt
Posts: 10316
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: cron job not being run

Wed Jun 26, 2019 10:39 pm

LTolledo wrote:
Wed Jun 26, 2019 9:39 pm
have you made your script "executable"

check out how to use:

Code: Select all

chmod
OP isn't using shell script in his example. It's just a command (date) and file redirect.

As to the problem, try using the full path for "date". Cron doesn't have your normal environment.

User avatar
jojopi
Posts: 3076
Joined: Tue Oct 11, 2011 8:38 pm

Re: cron job not being run

Wed Jun 26, 2019 11:14 pm

piman1947 wrote:
Wed Jun 26, 2019 9:04 pm
I am attempting to learn how to use cron on the raspberry Pi.
Are you really attempting to learn about cron, or are you attempting to fix a problem with "mydevices agent" or whatever?
5 * * * * date >> /home/pi/testing_cron

which I believe should run the date command every hour at 5 minutes past the hour
and then append the date to the file /home/pi/testing_cron. This NOT happening.
That is a totally correct line for a user crontab, and I cannot realistically see it failing unless there is a typo in the actual file. The fact that nothing like it is mentioned in /var/log/cron suggests it is not present at all. Check by running "crontab -e" again. (No, the command does not need a full path.)
Jun 26 20:05:02 raspberrypi CRON[26456]: (root) CMD (/etc/myDevices/crontab.sh)
Jun 26 20:05:02 raspberrypi CRON[26448]: (CRON) info (No MTA installed, discarding output)

which seem to be added to the file every minute.
Do you know why this job is running? It is not a normal thing unless you have installed it or something that created it. And it is running as root.

Every minute is really too frequent for cron, because of all the logging it does. It would be better to run continuously and then sleep for say 50 seconds after every operation.

The MTA message means that the job produced output that was not directed to a file. cron would have sent that output by email, if you had configured a mail transport agent.

User avatar
rpdom
Posts: 14437
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: cron job not being run

Thu Jun 27, 2019 5:10 am

What jojopi said is important. There seems to be something running that possibly shouldn't and whatever it outputs is being ignored.

It would be interesting to see what the file /etc/myDevices/crontab.sh contains and also what sudo crontab -l reports

User avatar
neilgl
Posts: 519
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: cron job not being run

Thu Jun 27, 2019 9:33 am

Are you running the Cayenne agent on that pi?

piman1947
Posts: 19
Joined: Wed Apr 02, 2014 4:05 am

Re: cron job not being run

Thu Jun 27, 2019 8:28 pm

First let me thank all the users who responded to my post. The problem appears to be that I had to put in the full path name
/bin/date for the date command. As to the other entries in the syslog file that are generated every minute, I still don't know
what command is being executed but since is the first time, I have been using the cron, I assume that they came with the system.
If anyone has a suggestion of how I can prevent that command from running or simply set crontab back to the initial
state, I would be interested.

As to the contents of the files /etc/myDevices/crontab.sh and the output of "sudo crontab -l" they are as follows:

A. /etc/myDevices/crontab.sh:

#!/bin/bash
#
# myDevices watchdog

SERVICE=service
GREP=/bin/grep
PS=/bin/ps
NOP=/bin/true
DATE=/bin/date

. /lib/lsb/init-functions


echo "myDevices agent cron job" > /var/log/cron
check_service_and_run() {
eval 'status_of_proc -p $1 /usr/bin/$2 $2'
ret_code=$?
if [ $ret_code != 0 ]; then
echo "Restarting service $2" >> /var/log/cron
sudo service $2 restart >> /var/log/cron
fi
}

check_service_and_run /var/run/myDevices/cayenne.pid myDevices

#rm /var/log/cron.log
rm -rf /var/log/SystemInformation.log
rm -rf /var/log/daemon*

exit



B. "sudo crontab -l:

* * * * * /etc/myDevices/crontab.sh

User avatar
neilgl
Posts: 519
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: cron job not being run

Thu Jun 27, 2019 10:58 pm

Ah, you are running cayenne agent. So maybe uninstall it as per their github

Code: Select all

sudo /etc/myDevices/uninstall/uninstall.sh

Return to “Beginners”