Search code examples
pythonpython-3.xamazon-web-servicesamazon-ec2cron

Scheduled cron job not getting executed


I have a cron job scheduled as follows inside an EC2 instance operating on Amazon Linux OS:

51 7 * * * /usr/bin/python3 /home/ec2-user/set_access_token.py > /home/ec2-user/access_token_logs.txt

The job is not getting executed despite providing the native path of python3 and specifying the time to run in UTC.

I am not getting any cron logs inside the /var/log folder


Solution

  • Did you run the script using the same command (/usr/bin/python3 /home/ec2-user/set_access_token.py) and check for any errors? If this script run very well, Update the cron job to send both standard output (stdout) and standard error (stderr) to the log file:

    51 7 * * * /usr/bin/python3 /home/ec2-user/set_access_token.py > /home/ec2-user/access_token_logs.txt 2>&1
    

    After making these changes, wait for the cron job to run again at the scheduled time, and then check the contents of /home/ec2-user/access_token_logs.txt for any error messages.