Crontab entries ignored on Amazon Linux 2 instance

0

I really can't figure out how one is supposed to set up periodic jobs on those instances. Should I use crontab -e? anacron? The crontab service is running, but not logging anything in journalctl except for edits through crontab -e.

I tried various commands, with and without the user field, and nothing ever gets executed.
Here is what I did:

sudo crontab -e
sudo crontab -l
1 * * * * echo foobar >> /tmp/cron-log 2>&1

I also tried to edit /etc/crontab directly, to add this line:

1 ** ** ** ** root echo foobar >> /tmp/cron-log 2>&1

sudo service crond status

● crond.service - Command Scheduler
   Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2019-10-05 11:35:27 UTC; 5 days ago
 Main PID: 3236 (crond)
   CGroup: /system.slice/crond.service
           └─3236 /usr/sbin/crond -n

journalctl | grep -i cron | grep jobs

Oct 10 02:01:01 ip-172-31-43-96.us-east-2.compute.internal anacron[25202]: Normal exit (0 jobs run)
Oct 11 00:01:01 ip-172-31-43-96.us-east-2.compute.internal anacron[28268]: Normal exit (0 jobs run)
Oct 11 01:01:01 ip-172-31-43-96.us-east-2.compute.internal anacron[31336]: Normal exit (0 jobs run)
Oct 11 02:01:01 ip-172-31-43-96.us-east-2.compute.internal anacron[1942]: Normal exit (0 jobs run)

journalctl |grep -i cron|tail -20

Oct 11 03:35:11 ip-172-31-43-96.us-east-2.compute.internal sudo[6988]: ec2-user : TTY=pts/0 ; PWD=/home/ec2-user ; USER=root ; COMMAND=/bin/crontab -e
Oct 11 03:35:11 ip-172-31-43-96.us-east-2.compute.internal crontab[6989]: (root) BEGIN EDIT (root)
Oct 11 03:35:34 ip-172-31-43-96.us-east-2.compute.internal crontab[6989]: (root) REPLACE (root)
Oct 11 03:35:34 ip-172-31-43-96.us-east-2.compute.internal crontab[6989]: (root) END EDIT (root)
Oct 11 03:36:01 ip-172-31-43-96.us-east-2.compute.internal crond[3236]: (root) RELOAD (/var/spool/cron/root)

This is beginning to drive me crazy, any help would be appreciated!
Franck

Edited by: franck102 on Oct 10, 2019 9:08 PM

gefragt vor 5 Jahren4857 Aufrufe
3 Antworten
1

RandyTakeshita wrote:
Hi,
Was your original intention to run the command every 1 minute?
If yes, your cron job should look like the following after typing crontab -e:

* * * * * echo foobar >> /tmp/cron-log 2>&1

Arrgh, indeed, thanks!

So this finally works, after I gave up on /etc/crontab and crontab -e, and instead created my own file in /etc/cron.d.

Franck

beantwortet vor 5 Jahren
0

A bit more info: the instance is using cronie; still no idea why nothing gets executed...

[ec2-user@ip ~]$ sudo yum list installed | grep -i cron
cronie.x86_64                         1.4.11-19.amzn2                installed
cronie-anacron.x86_64                 1.4.11-19.amzn2                installed
crontabs.noarch                       1.11-6.20121102git.amzn2       installed
[ec2-user@ip ~]$ repoquery --list cronie.x86_64
/etc/cron.d
/etc/cron.d/0hourly
/etc/cron.deny
/etc/pam.d/crond
/etc/sysconfig/crond
/usr/bin/crontab
/usr/lib/systemd/system/crond.service
/usr/sbin/crond
/usr/share/doc/cronie-1.4.11
/usr/share/doc/cronie-1.4.11/AUTHORS
/usr/share/doc/cronie-1.4.11/COPYING
/usr/share/doc/cronie-1.4.11/ChangeLog
/usr/share/doc/cronie-1.4.11/INSTALL
/usr/share/doc/cronie-1.4.11/README
/usr/share/man/man1/crontab.1.gz
/usr/share/man/man5/crontab.5.gz
/usr/share/man/man8/cron.8.gz
/usr/share/man/man8/crond.8.gz
/var/spool/cron

It is unclear whether cronie actually uses the /etc/crontab file, so I created a file in /etc/cron.d - still nothing executed :(

[ec2-user@ip cron.d]$ cat influx-update
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
1 * * * * root echo foobar >> /tmp/cron-log 2>&1

Edited by: franck102 on Oct 10, 2019 9:36 PM

beantwortet vor 5 Jahren
0

Hi,
Was your original intention to run the command every 1 minute?
If yes, your cron job should look like the following after typing crontab -e:

* * * * * echo foobar >> /tmp/cron-log 2>&1

The way you currently have it setup with the "1" in the first position means that the cron job will run once every hour... i.e. 6:01am, 7:01am, 8:01am, etc...

Hope this helps,
-randy

beantwortet vor 5 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen