2
votes

I recently setup a cron job on my EC2 instance. I have my file "test.py" uploaded to this instance and would like it to run at a set time every week.

The type of instance I am using is Amazon Linux AMI 2018.03.0 (HVM)

From within my EC2 instance using PuTTy I used crontab -e to edit the crontab file. I entered:

30 12 * * 2 python /home/ec2-user/test.py 

to have it run every Tuesday at 12:30.

Now, whenever I do crontab -l the newly created cron is shown but it has not been running for whatever reason.

Did I use the wrong file path for my test.py file that's on the EC2 instance?

I am unsure as to how to progress.

2

2 Answers

1
votes

first check, whether this line ("python /home/ec2-user/test.py") is running properly or not on your console. If yes, then you have to add path in your crontab. you can copy all the paths from path variable using "echo $PATH" and along with add the path of the folder where your test.py is present. and paste it at the top of your crontab. eg - PATH = /home/ubuntu/anaconda3/bin: ... :/home/ec2-user 30 12 * * 2 python /home/ec2-user/test.py

1
votes

Amazon Linux doesnt like crontab -e. instead take the same config and place it in /etc/cron.d/ with any name you want without any extension and be done with it. Make sure you change the permissions to 0644 on the file you save. It will execute based on the time schedule you set.