Crontab Is Not Working on Amazon Ec2 Server

Cannot get cron to work on Amazon EC2?

Cron can be run in Amazon-based linux server just like in any other linux server.

  1. Login to console with SSH.
  2. Run crontab -e on the command line.
  3. You are now inside a vi editor of the crontab of the current user (which is by default the console user, with root permissions)
  4. To test cron, add the following line: * * * * * /usr/bin/uptime > /tmp/uptime
  5. Now save the file and exit vi (press Esc and enter :wq).
  6. After a minute or two, check that the uptime file was created in /tmp (cat /tmp/uptime).
  7. Compare it with the current system uptime by typing the uptime command on the command line.

The scenario above worked successfully on a server with the Amazon Linux O/S installed, but it should work on other linux boxes as well. This modifies the crontab of the current user, without touching the system's crontabs and doesn't require the user inside the crontab entry, since you are running things under your own user. Easier, and safer!

crontab not working in AWS EC2 instance

You can set environment variables for cron.

Do you try to check following environment variables ?

  • HOME

    • It indicates cron user's home directory. I guess it's defined as "/"
  • PATH

    • It defines cron user's $PATH. Please this variable also.

You can see example crontab from /etc/crontab

$ cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# For details see man 4 crontabs

# 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

Django-crontab is not working on in linux ec2 instance

Atleast I found the answer myslef. Freezing the pip3 modules and installing it in the server environment solved my issue. MODULE_IMPORT ERROR can be rectified by this method even if your module is not visible when installed manualy using pip3 install module-name. I hope this works for others!



Related Topics



Leave a reply



Submit