- Neueste
- Die meisten Stimmen
- Die meisten Kommentare
Thank you Sri for your detailed response! For your local crontab -e
example, I don't think you want to specify the user. After seeing your post, I tried crontab -e
again and installed a * * * * *
test script to echo the date into a test file and it worked. I was able to see the test file and the date written inside was updated every minute.
Unfortunately, when I change it specify the hour and minute, the scheduled job does not run. I suspect this is due to time zone issue so I added a CRON_TZ=America/Los_Angeles
in my crontab for PST time zone. That didn't work either. Then I tried scheduling using UTC time and that worked....
So, how do I change the time zone for crontab? My system time is already set to PST. I see it when I type date
in the shell. The man page for cron says "The daemon will use, if present, the definition from /etc/timezone for the timezone." when I cat /etc/timezone
it says "America/Los_Angeles".
I'm not sure why there's a time zone mismatch.
Hi, Good Question
I was curious about this, so I have setup a Ubuntu 20.04
and I was able to use crontab.
crontab's are generally setup per user. when you login, you would be logging in as a ec2-user.
Let's assume that you have logged in as ec2-user
, so you could check if there is a crontab by running crontab -l
. If there is no crontab then you would see something like the following
crontab -l
no crontab for ubuntu
to add a crontab, you could use crontab -e
, use the editor of your choice and add a line like
17 * * * * root cd / && run-parts --report /etc/cron.hourly
then restart sudo service cron restart
Next you can check sudo service cron status
and then crontab -l
returns
17 * * * * root cd / && run-parts --report /etc/cron.hourly
If you need to setup crontab for root, you can use sudo crontab -e
or if it's for another user then crontab -u
Also check if you have this file
cat /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
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
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 )
#
Relevanter Inhalt
- AWS OFFICIALAktualisiert vor 8 Monaten
- AWS OFFICIALAktualisiert vor 2 Jahren
- Wie kann ich meine sekundäre Netzwerkschnittstelle in meiner Ubuntu EC2-Instance zum Laufen bringen?AWS OFFICIALAktualisiert vor einem Jahr
I haven't personally verified these but you are welcome to try them. There are lots of comments but not all of them work https://askubuntu.com/questions/54364/how-do-you-set-the-timezone-for-crontab