I am trying to set up a cron job, by creating a file /etc/cron.d/myjob
:
55 * * * * t echo hello > /tmp/cron.log && cd /tmp/test/ && pwd > /tmp/cron.log
I tried to verify if the job is scheduled successfully, by using the redirections. I created the file at 21:50, and when 5 minutes later i.e. it is 21:55, there is still no /tmp/cron.log created. I was wondering why?
I specify the user to be t
for the job in /etc/cron.d/myjob
. But whose is the cron job? I am not sure about it, so I tried the two commands below. Neither shows the job I created.
$ crontab -l
no crontab for t
$ sudo crontab -l
[sudo] password for t:
no crontab for root
My /etc/crontab doesn't explicitly read from the files under /etc/cron.d/. See below. Can that be the reason that my cron job isn't running? Thanks.
# /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 )
#
Update:
Thanks to Jeff. change permission on /etc/cron.d/myjob
to rw-r--r--
solves the problem.
Why does the original rw-rw-r--
permission of my job file not work, but rw-r--r--
is required? Do the files under /etc/cron.d/
and /etc/cron.daily/
must have the same permissions rw-r--r--
?
Why does /etc/crontab
not need to explicitly read the files under /etc/cron.d/
?
man 5 crontab
explicitly mentions /etc/cron.d/ being used as you describe, but I suspect some cron daemons don't do that. – l0b0 Oct 30 '18 at 02:09man 5 crontab
, but you could also look at which*cron*
packages you have installed. – l0b0 Oct 30 '18 at 02:10rw-rw-r--
not work. I am not sure why/etc/crontab
doesn't need to explicitly read the files under/etc/cron.d/
. – Tim Oct 30 '18 at 02:35