Cannot get cron to work on Amazon EC2?
Cron can be run in Amazon-based linux server just like in any other linux server.
- Login to console with SSH.
- Run
crontab -e
on the command line. - You are now inside a vi editor of the crontab of the current user (which is by default the console user, with root permissions)
- To test cron, add the following line:
* * * * * /usr/bin/uptime > /tmp/uptime
- Now save the file and exit vi (press Esc and enter :wq).
- After a minute or two, check that the uptime file was created in /tmp (
cat /tmp/uptime
). - 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
Using Bash Environment Variables from Within a Perl Script
Linux: Modpost Does Not Build Anything
Linux:How to Set Default Route from C
Stty Serial Port Settings for Parity Not Persistent
Quick Unix Command to Display Specific Lines in the Middle of a File
Bash History Without Line Numbers
How Is It Possible That Kill -9 for a Process on Linux Has No Effect
Limiting the Time a Program Runs in Linux
How to Use Aliased Commands with Xargs
Given a Linux Username and a Password How to Test If It Is a Valid Account
Logrotate to Clean Up Date Stamped Files
Simple Way to Convert Hh:Mm:Ss (Hours:Minutes:Seconds.Split Seconds) to Seconds
How to Parse Netstat Command in Order to Get Process Name and Pid from It
Rsync - Mkstemp Failed: Permission Denied (13)
Genymotion Throws Libssl_Conf.So: Cannot Open Shared Object File: No Such File or Directory
After Changing /Etc/Profile, What Do I Have to Do to Reset My Shell